Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The RelayCommand isn't a RoutedCommand, which I think is where you ending up confused.</p> <p>The constructors for the Relay command take an <a href="http://msdn.microsoft.com/en-us/library/018hxwa8.aspx" rel="nofollow noreferrer">Action delegate</a> and optional <a href="http://msdn.microsoft.com/en-us/library/bfcke1bz.aspx" rel="nofollow noreferrer">Predicate delegate</a>. These delegates don't take an EventArgs, just the single Object parameter, which is why you are encountering an error. The predicate also requires a return type of bool, which is the next error you'll get. In the CanExecute predicate instead of setting e.CanExecute like you do with a RoutedCommand you simply return true/false.</p> <p>Here's how it should look:</p> <pre><code>public ICommand RelayCommand_MoveUp { get { if (_relayCommand_MoveUp == null) { _relayCommand_MoveUp = new RelayCommand(Execute_MoveUp, CanExecute_MoveUp); } return _relayCommand_MoveUp; } } private void Execute_MoveUp(object sender) { if (_selectedFolder != null) { _selectedFolder.SelectParent(); } } private void CanExecute_MoveUp(object sender) { return (_selectedFolder != null) &amp;&amp; (_selectedFolder.Parent != null); } </code></pre> <p><br/><br/> <strong>EDIT (Added from discussion in comments):</strong></p> <p>If you want to use something more like the RoutedCommands, which will make the ViewModels more dependent on WPF specific views, there are some good options available.</p> <p>This <a href="http://groups.google.com/group/wpf-disciples/browse_thread/thread/40f387caac2f1e13?pli=1" rel="nofollow noreferrer">discussion</a> got the whole idea of using RoutedCommands in conjunction with MVVM started.</p> <p>And <a href="http://www.codeproject.com/KB/WPF/VMCommanding.aspx" rel="nofollow noreferrer">here's</a> a very solid solution to the issues presented by Josh Smith and Bill Kempf.</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