This project has moved and is read-only. For the latest updates, please go here.

Difference in Command , RelayCommand & EventToCommand ?

Apr 8, 2010 at 11:31 AM

Hi Laurent,

I am new to Silver Light and MVVM and just 2,3 days back while googling I found MVVM Light toolkit ... and till now what I have explored it is really great  , thanks for this wonderful effort :)

Please excuse my ignorance as I told you I am new to Silverlight & MVVM , actually I am little confused till now between Command , RelayCommand & EventToCommand. I have downloaded your MIX10 code samples and have looked at your RelayCommand & Command samples ... what is difference between Command & RelayCommand ? If one has RelayCommand then why would he/she will be using simple Command by inheriting from ICommand ?

And if I am using RelayCommand then when and why I need to use EventToCommand , does RelayCommand only work for simple Button base control's Click Events ??? 


Purpose of EventToCommand is just to pass the EventArgs to ViewModel ? If i violate the MVVM pattern ...then I can handle all events in code behind.. so then do I need to use EvetToCommand ?

Thanks for your support & time.


Apr 12, 2010 at 8:49 AM


First thing you want to do is spell it Silverlight (one word, one capital) :)

You got it absolutely right: ICommand is the interface that is present in the framework. You can of course implement your own ICommand classes. RelayCommand is one implementation of ICommand that is encapsulated. Its goal is to react when invoked and to relay the invocation to methods (using delegates or lambda expressions). The end result is that you do not need to write your own ICommand implementation, thus you have less code to maintain.

As for EventToCommand, it works around a problem in Silverlight: Commands are only available on Buttons (and other clickable controls like RadioButton, Checkbox, ToggleButton, etc...), and only when the control is clicked. For all other elements and all other events, there is no solution out of the box. The EventToCommand is a Blend behavior that allows binding any event of any UIElement to a command. What you mention about EventArgs and the ability to pass it to the command is really just a side effect.

For more information about commands, you can read this article:

About EventToCommand:

Finally, I have a short explanation of Commands as well as a demo comparing a classical implementation of ICommand to the RelayCommand in my MIX10 talk:



Apr 15, 2010 at 6:37 AM

Thanks a lot  Laurent  for your help and this great toolkit :)