views:

1115

answers:

1

I have been using the DelegateCommand found in the MVVM Visual Studio template at CodePlex. This works very nicely for having Views be able to execute commands on their ViewModel.

I read somewhere that in MVVM "attached behaviors" should be used. As far as I can tell, "attached behaviors" are the same type of pattern as DelegateCommand but are used by Silverlight since it does not have commands.

Is this correct? Or are "attached behaviors" something different in kind and worth learning in addtiion to DelegateCommand?

+3  A: 

A DelegateCommand (or a RelayCommand, which is almost the same but accepts a parameter) is just a light-weight implementation of the ICommand interface that allows a ViewModel to expose commands easily.

Attached behaviors are a way to link an event to a command. For instance, most WPF controls don't have a Command property, so you can't normally define a command to react to their events. With attached behaviors, you can "bind" any event of any control to a command of your ViewModel. Have a look at Marlon Grech's implementation, which seems the most flexible to me

Thomas Levesque