What is the firing order of WPF events?
Instantiating a WPF Window
When you instantiate a WPF Window, each element is initialized from the bottom up. Deeply nested UI elements are initialized first. Here is the sequence of events:
- The user interface element is instantiated
- The element's BeginInit() method is invoked
- The XAML parser sets all element properties and adds any content
- The element's EndInit() method is invoked
- The element's Initialized event fires and its IsInitialized property is set to true
- After initialization is complete for all elements and it's fired for the Window, the Loaded event is fired in reverse order--from the containing Window down to the most deeply nested elements and the IsLoaded property is set to true. When Loaded has fired for all elements, the window becomes visible and its elements are rendered.
- The Window's ContentRendered event fires after the window has been rendered, visibile, and ready for input
- The Window's SourceInitialized event fires when the HwndSource property of the window is acquired but before it's made visible
- The Window's Activated event fires
Closing a WPF Window
Here is the sequence of events when closing a WPF Window:
- The Closing event fires. You can prevent the Window from closing by setting the CancelEventArgs.Cancel property to true
- The Deactivated event fires
- The Closed event fires after the Window is closed, but you can still access form elements
- The Unloaded event fires
Activating and Deactivating Windows
The Deactivated event fires when switching away from the window to another window or another application.
The Activated event not only occurs when the form is first instantiated, but also when the user switches to this window from another window or from another application.
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/26/18
Comment or report problem with topic
