#613 – Window Event Sequence
July 30, 2012 5 Comments
The full sequence of events fired for a Window object are as follows.
On application startup, if the Window is the application’s main window. (Application events are also shown in the correct sequence).
- Application.Startup
- Window.Initialized
- Window.IsVisibleChanged
- Window.SizeChanged
- Window.LayoutUpdated
- Window.SourceInitialized
- Application.Activated
- Window.Activated
- Window.PreviewGotKeyboardFocus
- Window.IsKeyboardFocusWithinChanged
- Window.IsKeyboardFocusedChanged
- Window.GotKeyboardFocus
- Window.LayoutUpdated
- Window.Loaded
- Window.ContentRendered
On normal application shutdown, the event sequence is:
- Window.Closing
- Window.IsVisibleChanged
- Window.Deactivated
- Application.Deactivated
- Window.IsKeyboardFocusWithinChanged
- Window.IsKeyboardFocusedChanged
- Window.LostKeyboardFocus
- Window.Closed
- Application.Exit
When application/window loses focus (user switches to another application):
- Window.Deactivated
- Application.Deactivated
- Window.IsKeyboardFocusWithinChanged
- Window.IsKeyboardFocusedChanged
- Window.LostKeyboardFocus
When application/window gains focus (user switches back to application):
- Application.Activated
- Window.Activated
- Window.PreviewGotKeyboardFocus
- Window.IsKeyboardFocusWithinChanged
- Window.IsKeyboardFocusChanged
- Window.GotKeyboardFocus
Pingback: Dew Drop – July 30, 2012 (#1,374) | Alvin Ashcraft's Morning Dew
Pingback: Application Event Sequence in WPF | Around computing
Hmm, Window.Initialized is traditionally called in the classes constructor right? So are the succeeding actions called AFTER the constructor returns? Or during the Initialized method?
Ok never mind, I just just hooked up to all the events and the IsVisablityChanged fired after the constructor has returned. I think it’s more difficult to identify what content you should be placing is the correct event. Such as getting a hwnd reference would go in the Window.SourceInitialized event
It seems that OnLoaded is only fired first when one of the SizeToContent=”xxx” is specifed.
When absent or if Width and Height are specified, OnSourceInitialized will fire first.