Loaded - Initialized - SourceInitialized

I'm hoping someone can help out here ... I'm trying to figure out exactly what these events "mean".

Certainly, most sample code uses the Loaded event to mean "this object and its descendants are completely ready to go".

However, I'm fairly certain I saw something from a WPF team member stating that -- at least for a Window -- the SourceInitialized event is a "safer" option. (This event is only available for Window objects.)

And in the midst of all that, what about the Initialized event What does that tell me I started using this for non-Window objects on the theory that it was the non-Window "analog" of the "better" SourceInitialized event, but it turns out that certain things (such as Focus( )) don't work very well there.

Summary:

  • For a Window, what's the difference between the Loaded and SourceInitialized events
  • For a FrameworkElement, what's the difference between the Loaded and Initialized events

Thanks a bunch!



Answer this question

Loaded - Initialized - SourceInitialized

  • Bajrang

  • astallings

    Window.SourceInitialized is raised after a Window's HwndSource is created, but before the window itself is shown.


  • Arash66451

    I would suggest that you implement them all and put breakpoints in them and see what the status of the object is.

    Was it loaded Is Data Bound, etc etc.

    I assume that Initialized comes right after an element has been created and initialized. Kind of the step after the item has been created. Often we see initialization code in the constructor. Althought i could be wrong in this assumption.


  • Ocherk

    Thanks, viliescu, for the link -- that was helpful.

    However, the article still doesn't address Window.SourceInitialized.

    I'll do some investigation of my own, and if I can make (more) sense of this, I'll post my findings here.

    And, of course, if anyone else wants to add comments, please do.

    -- Matt


  • williamosullivan

    Further: System.Windows.Window will only have a window handle created after the HwndSource has initialized itself.
  • Loaded - Initialized - SourceInitialized