C#-WPF-UserControl-生命周期(加载 退出)

C#-WPF-UserControl-生命周期(加载 退出)

My_Initialize()放在public UC_GaussianFilter(){}中,无法执行

My_Initialize()必须放在private void My_Loaded(){}

cs 复制代码
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


    public partial class UC_GaussianFilter : UserControl
    {

        private string TAG = "";
        public UC_GaussianFilter()
        {
            InitializeComponent();
            TAG = this.GetType().Name;
            //My_Initialize();
            this.Unloaded += My_Unloaded;
            this.Loaded += My_Loaded;
        }

        private void My_Loaded(object sender, RoutedEventArgs e)
        {
            My_Initialize();
            Debug.WriteLine($"类:{TAG}  方法名{MethodBase.GetCurrentMethod().Name}   功能:加载");
        }

        private void My_Initialize()
        {
            try
            {
                Debug.WriteLine($"类:{TAG}  方法名{MethodBase.GetCurrentMethod().Name}   功能:初始化");
            }
            catch (Exception e)
            {
                Debug.WriteLine($"类:{TAG}  方法名{MethodBase.GetCurrentMethod().Name}   功能:错误");
            }
            
        }
        private void My_Unloaded(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine($"类:{TAG}  方法名{MethodBase.GetCurrentMethod().Name}   功能:退出");
        }
    }
相关推荐
后台模板学习30 分钟前
Rust vs Python 在用户认证模块中的实现:底层
开发语言·python·rust
所念皆星海91138 分钟前
Python学习---DAY10函数
开发语言·python·学习
wuyk5553 小时前
104.C 语言字节对齐:从底层原理到工程实践的完整指南
c语言·开发语言·stm32·单片机·嵌入式硬件
君顾19 小时前
智慧零售实战指南:从技术架构到落地方案全解析
java·开发语言·零售
北域码匠9 小时前
高通滤波算法深度解析(High-Pass Filter)
stm32·算法·c#·数字信号处理·嵌入式开发·滤波算法·高通滤波
南棱笑笑生9 小时前
20260904实测给飞凌OK3576-C开发板刷入Rockchip原厂的IMG固件【使用飞凌的DTS】切换串口波特率为1.5Mbps
c语言·开发语言·rockchip
平头哥技术团队10 小时前
Day 10 | 工欲善其事:VS Code 配置与项目归档
android·开发语言·前端·javascript·html·交互
乌萨奇也要立志学C++10 小时前
【洛谷】kmp算法
开发语言·算法
传奇开心果编程10 小时前
【Rust入门知识点学与练】第4课:条件判断 if / else
开发语言·学习·rust
m0_3807438710 小时前
给 Claude API 调用补上超时重试和错误分类
开发语言·人工智能·php