Note that there are some explanatory texts on larger screens.

plurals
  1. POMVVM Light Toolkit - RelayCommands, DelegateCommands, and ObservableObjects
    text
    copied!<p>I just started experimenting with Laurent Bugnion's <a href="http://mvvmlight.codeplex.com/" rel="nofollow">MVVM Light Toolkit</a>. I think I'm going to really like it, but I have a couple questions.</p> <p>Before I get to them, let me explain where I'm coming from. I currently use a combination of Josh Smith's <a href="http://mvvmfoundation.codeplex.com/" rel="nofollow">MVVM Foundation</a> and another project on Codeplex called <a href="http://wpf.codeplex.com/releases/view/14962" rel="nofollow">MVVM Toolkit</a>. I use <code>ObservableObject</code> and <code>Messenger</code> from MVVM Foundation and <code>DelegateCommand</code> and <code>CommandReference</code> from MVVM Toolkit.</p> <p>The only real overlap between MVVM Foundation and MVVM Tookit is that they both have an implementation for <code>ICommand</code>: MVVM Foundation has <code>RelayCommand</code> and MVVM Tookit has <code>DelegateCommand</code>. Of these two, <code>DelegateCommand</code> appears to be more sophisticated. It employs a <code>CommandManagerHelper</code> that uses weak references to avoid memory leaks.</p> <p>With that said, here are my questions:</p> <ol> <li><p>Why does MVVM Light use <code>RelayCommand</code> rather than <code>DelegateCommand</code>? Is the use of weak references in an <code>ICommand</code> unnecessary or not recommended for some reason?</p></li> <li><p>Why is there no <code>ObservableObject</code> in MVVM Light? <code>ObservableObject</code> is basically just the part of <code>ViewModelBase</code> that implements <code>INotifyPropertyChanged</code>, but it's very convenient to have as a separate class because view-models are not the only objects that need to implement <code>INotifyPropertyChanged</code>. For example, let's say you have a DataGrid that binds to a list of <code>Person</code> objects. If any of the properties in <code>Person</code> can change while the user is viewing the DataGrid, <code>Person</code> would need to implement <code>INotifyPropertyChanged</code>. (I realize that if <code>Person</code> is auto-generated using something like LinqToSql, it will probably already implement <code>INotifyPropertyChanged</code>, but there are cases where I need to make view-specific versions of entity model objects, say, because I need to include a command to support a button column in a DataGrid.)</p></li> </ol> <p>Thanks.</p> <p>P.S. Here is the code for <code>DelegateCommand</code> from the MVVM Toolkit:</p> <p><a href="https://docs.google.com/document/pub?id=1ApCx5SbCfHi5fBhv8Ki3zA6j34sp2t80LQZdj89v8cU" rel="nofollow">https://docs.google.com/document/pub?id=1ApCx5SbCfHi5fBhv8Ki3zA6j34sp2t80LQZdj89v8cU</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload