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}   功能:退出");
        }
    }
相关推荐
利威尔xu39 分钟前
Go Mutex 饥饿模式:正常模式等待者饿死,1ms 阈值自动切换崩溃
开发语言·后端·面试·golang·并发编程
乌暮2 小时前
少写重复 CRUD:用大白话搞懂 MyBatis-Plus
java·开发语言·spring boot·面试·mybatis
不绝1912 小时前
Lua基础语法入门:注释、变量类型与字符串操作
开发语言·lua
Hhy_11073 小时前
《C++深度解构07》手撕 vector —— 从底层三指针架构到迭代器失效彻底吃透
c语言·开发语言·c++·学习·visual studio
风落青芜3 小时前
链式二叉树的实现与基本操作
c语言·开发语言·数据结构·算法
艾莉丝努力练剑4 小时前
【QT】系统相关:TCP的API介绍
开发语言·前端·c++·人工智能·qt·学习·tcp/ip
BruceNeter4 小时前
C# winform卡死问题分析1——线程池子线程创建句柄
c#·.net
wuxianda10305 小时前
Swift 项目用 Xcode 脚手架起步:默认工程结构和依赖组合为什么会被识别成同源
开发语言·xcode·swift·4.3a·appstore审核
ShineWinsu5 小时前
对于Qt:QVBoxLayout常见属性以及方法的解析
开发语言·数据库·c++·qt·gui·客户端·布局管理器
Sarvartha5 小时前
反射综合案例:SQL 语句生成
java·开发语言