how to call a window's Loaded event in WPF MVVM?

bluebit picture bluebit · Aug 3, 2009 · Viewed 19.4k times · Source

It is easy enough to create a command from my OnLoaded() event handler code, but how do I call it from the View?

<window Loaded="onLoaded"> doesn't cut the cake anymore since it calls code in the xaml.cs. How would I create an ICommand equivalent?

Answer

Kent Boogaart picture Kent Boogaart · Aug 3, 2009

You can do this sort of thing via an attached behavior. To save yourself some time, take a looked at Marlon Grech's Attached Command Behavior library.