WPF:初始化和加载事件之间是什么? [英] WPF: What is between the Initialized and Loaded event?

查看:659
本文介绍了WPF:初始化和加载事件之间是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当窗口或控件首次显示时,我想运行一些代码。我不能使用加载,因为可以多次启动。我不能使用Initialized,因为这是由构造函数完成的。

I want to run some code when the Window or Control is first displayed. I can't use Loaded because that can fire more than once. I can't use Initialized because that is done by the constructor.

有没有事件之间?

推荐答案

不幸的是没有这样的事件。您可以在加载方法中使用布尔值来确保您的东西只会触发一次 -

Unfortunately there is no such event. You can use a boolean in the Loaded Method to make sure your stuff only fires once -

if(!IsSetUp)
{
   MySetUpFunction();
   IsSetUp = true;
}

在此查看WPF Windows生命周期事件:

Check out the WPF Windows lifetime events here:

http://msdn.microsoft.com /en-us/library/ms748948.aspx#Window_Lifetime_Events

alt text http://i.msdn.microsoft.com/dynimg/IC155674.png

这篇关于WPF:初始化和加载事件之间是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆