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.

Tim Cooper
  • 151,519
  • 37
  • 317
  • 271
Kent Boogaart
  • 170,894
  • 35
  • 387
  • 389
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,349
  • 4
  • 30
  • 48