#613 – Window Event Sequence

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

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

5 Responses to #613 – Window Event Sequence

  1. Pingback: Dew Drop – July 30, 2012 (#1,374) | Alvin Ashcraft's Morning Dew

  2. Pingback: Application Event Sequence in WPF | Around computing

  3. Will says:

    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?

    • Will says:

      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

  4. Yomodo says:

    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.

Leave a comment