控件中国网现已改版,您看到的是老版本网站的镜像,系统正在为您跳转到新网站首页,请稍候.......
中国最专业的商业控件资讯网产品咨询电话:023-67870900 023-67871946
产品咨询EMAIL:SALES@COMPONENTCN.COM

WPF 控件开发之 Lefitime Events for all Elements

作者:Alen 出处:Alen 2010年09月09日 阅读:

刚好做东东遇到这个问题,回头把MSDN和<Pro WPF in C# 2008>又翻了翻,记录下来当作备份。

如果以后还有人问,直接给ge链接给他,嘿嘿!
 

在WPF中,Element大体上来说有3个阶段. 并且有3个对应的事件
 

1. Initialized

2. Loaded
 

3. Unloaded
 

具体的内容大家可以看看MSDN的说明:
 

http://msdn.microsoft.com/zh-cn/library/ms754221.aspx
 

 

看完了后,这儿按顺序说说相关的一些东西


 

Step1:BeginInit()

    Xaml 解析器开始干活,Xaml被改变的的DP开始赋值
 

 

Step2: EndInit()

1. 完成初始化工作,发Initialized事件

2. 因为整棵LogicTree是按“叶子-〉根”的顺序创建的。所以现在当前Element它的logicTree已经都创建完成。但是请注意:

    1)  你不能说包含该Element的更大的LogicTree也被成功创建了!

    2)  该Element的Style设置,数据绑定并不一定完成!
 

 

Step3:Loaded

当所有的Element都Initialized后,Loaded 事件被触发

1.  按“根-〉叶子”的顺序发Loaded event,刚好和Initialized相反。

2. 当所有Element的Loaded事件都发完后,Window开始显示出来,并且开始Render Element

 

Step4:UnLoaded

好像这儿不用多说什么了

 

在Element的生存周期里,除了上面的,还有其他的一些状态,不想翻译组织了,直接抄过来,就是上面提到的那本书。大家也可以到MSDN中去看看

 

Name

Description

SourceInitialized

Occurs when the HwndSource property of the window is acquired (but before the window is made visible). The HwndSource is a window handle that you may need to use if you’re calling legacy functions in the Win32 API.

ContentRendered

Occurs immediately after the window has been rendered for the first time. This isn’t a good place to perform any changes that might affect the visual appearance of the window, or you’ll force a second render operation. (Use the Loaded event instead.) However, the ContentRendered event does indicate that your window is fully visible and ready for input.

Activated

Occurs when the user switches to this window (for example, from another window in your application or from another application). Activated also fires when the window is loaded for the first time. Conceptually, the Activated event is the window equivalent of a control’s GotFocus event.

Deactivated

Occurs when the user switches away from this window (for example, by moving to another window in your application or another application). Deactivated also fires when the window is closed by a user, after the Closing event but before Closed. Conceptually, the Deactivated event is the window equivalent of a control’s LostFocus event.

Closing

Occurs when the window is closed, either by a user action or programmatically using the Window.Close() method or the Application.Shutdown() method. The Closing event gives you the opportunity to cancel the operation and keep the window open by setting the CancelEventArgs.Cancel property to true. However, you won’t receive the Closing event if your application is ending because the user is shutting down the computer or logging off. To deal with these possibilities, you need to handle the Application.SessionEnding

event described in Chapter 3.

Closed

Occurs after the window has been closed. However, the element objects are still accessible, and the Unloaded event hasn’t fired yet. At this point, you can perform cleanup, write settings to a persistent storage place (such as a configuration file or the Windows registry), and so on.

 另外,如果你只想做一些简单的初始化设置,建议在Loaded 时去完,因为现在的Style,数据绑定等等都搞定了,可以说Element已经真正地完成了初始化创建。
 

WPF界面套包控件:ComponentOne Studio for WPF
中文介绍

WPF界面套包控件:RadControls for WPF
中文介绍

WPF流程图控件:AddFlow for WPF
中文介绍

更多WPF控件页面 

 

 

热推产品

  • ActiveReport... 强大的.NET报表设计、浏览、打印、转换控件,可以同时用于WindowsForms谀坔攀戀Forms平台下......
  • AnyChart AnyChart使你可以创建出绚丽的交互式的Flash和HTML5的图表和仪表控件。可以用于仪表盘的创......
首页 | 新闻中心 | 产品中心 | 技术文档 | 友情连接 | 关于磐岩 | 技术支持中心 | 联系我们 | 帮助中心 Copyright-2006 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 电话:023 - 67870900 传真:023 - 67870270 产品咨询:sales@componentcn.com 渝ICP备12000264号 法律顾问:元炳律师事务所 重庆市江北区塔坪36号维丰创意绿苑A座28-5 邮编:400020
在线客服
在线客服系统
在线客服
在线客服系统