MVVM Light Toolkit - RelayCommands, DelegateCommands, and ObservableObjects
Posted
by
DanM
on Stack Overflow
See other posts from Stack Overflow
or by DanM
Published on 2011-01-04T03:12:21Z
Indexed on
2011/01/04
4:54 UTC
Read the original article
Hit count: 1175
I just started experimenting with Laurent Bugnion's MVVM Light Toolkit. I think I'm going to really like it, but I have a couple questions.
Before I get to them, I need to explain where I'm coming from. I currently use a combination of Josh Smith's MVVM Foundation and another project on Codeplex called MVVM Toolkit. I use ObservableObject and Messenger from MVVM Foundation and DelegateCommand and CommandReference from MVVM Toolkit.
The only real overlap between MVVM Foundation and MVVM Tookit is that they both have an implementation for ICommand: MVVM Foundation has a RelayCommand and MVVM Tookit has a DelegateCommand. Of these two, DelegateCommand appears to be more sophisticated. It employs a CommandManagerHelper that uses weak references to avoid memory leaks.
With that said, a couple questions:
Why does MVVM Light Toolkit use
RelayCommandrather thanDelegateCommand? Is the use of weak references in anICommandunnecessary or not recommended for some reason?Why is there no
ObservableObjectin MVVM Light?ObservableObjectis basically just the part ofViewModelBasethat implementsINotifyPropertyChanged, but it's very convenient to have as a separate class because view-models are not the only objects that need to implementINotifyPropertyChanged. For example, let's say you have DataGrid that binds to a list ofPersonobjects. If any of the properties inPersoncan change while the user is viewing the DataGrid,Personwould need to implementINotifyPropertyChanged. (I realize that ifPersonis auto-generated using something like LinqToSql, it will probably already implementINotifyPropertyChanged, but there are cases where I need to make a view-specific version of entity model objects, say, because I need to include a command to support a button column in a DataGrid.)
Thanks.
© Stack Overflow or respective owner