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}   功能:退出");
        }
    }
相关推荐
jerryinwuhan22 分钟前
《Python数据预处理》第四章
开发语言·python
长江&后浪24 分钟前
防火墙的描述
开发语言·网络·php
观无1 小时前
若依EasyExcel实现单元格合并
开发语言·前端·javascript
雨晨源码(同名B站)1 小时前
基于Python的网易云音乐评论数据情感化分析系统 音乐爬虫信息可视化 |SnowNLP评论情感分析
开发语言·hadoop·爬虫·python·信息可视化·毕业设计
我不是疯子是傻子1 小时前
串口通信数据帧粘包拆包再进化:基于 Qt 的滑动窗口与 CRC 校验实战
开发语言·qt
程序员老陆1 小时前
Qt中实现窗口真全屏(覆盖Windows任务栏)
开发语言·windows·qt
霸道流氓气质2 小时前
Java中信号量(Semaphore):从本地到分布式
java·开发语言·分布式
Patrick在香港2 小时前
Python正则表达式实战:解析和验证香港身份证、车牌、电话格式
开发语言·python·正则表达式
路溪非溪2 小时前
Python语言的执行流程总结
开发语言·python
民乐团扒谱机2 小时前
【超详解】量子克拉美罗下界QCRB:时延估计精度极限推导+MATLAB多场景绘图实战
开发语言·机器学习·matlab·量子力学·qcrb