9

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?

2 Answers2

10

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.

Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
5

You could use the MVVM Light Toolkit's event to command behavior: http://blog.galasoft.ch/archive/2009/11/05/mvvm-light-toolkit-v3-alpha-2-eventtocommand-behavior.aspx

Justin
  • 2,399
  • 4
  • 31
  • 50