.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> WPF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Load and Initialize in WPF

Posted By:nishithraj       Posted Date: December 28, 2009    Points: 25    Category: WPF    URL: http://www.dotnetspark.com  

WPF has both a Loaded even and an Initialized event. Initializing and loading a control tend to happen at about the same time, and consequently these events fire at roughly the same time.
 

WPF has both a Loaded even and an Initialized event. 
Initializing and loading a control tend to happen at about the same time, and consequently these events fire at roughly the same time. 

1)  The Initialized event is for the element creation and to set all its property

2)  The Loaded event will built and initialize the element and also it runs on the layout, data has been bound.

Initialized Event
ISupportInitialize is the interface used to intialize the elements, and when the EndInit method of that interface is called, the IsInitialized property is set to true, and the Initialized event is fired.

 For example, in this Xaml:

the Button will be created, BeginInit will be called, the Width property will be set, the Content property will be set (to "Testing"), and then EndInit will be called.


Loaded Event
The Loaded event fires when an element is not only initialized, but it is about to be rendered.

The motivation for the Loaded event is the typical scenario where you want to do some initialization in your application at load-time. 

Loaded event fires after layout and data binding have had a chance to run, but just before the first render.  (And note that if you do anything in your Loaded event handler that invalidates layout, it might be necessary to re-run it before rendering.)

Following is the life cycle of a simple button

Button.IsInitialized goes true
Button.Initialized event is raised
Page.IsInitialized goes true
Page.Initialized event is raised
Page IsLoaded goes to true
Button IsLoaded goes to true
Page.Loaded is raised
Button.Loaded is raised

 

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend