I am applying the MVVM pattern per Josh Smith and having difficulty. I've been researching the problem here and can't seem to get the syntax quite right.
The code below looks to me like it follows the required syntax, but Visual Studio reports error "Delegate 'System.Action' does not take '2' arguments" on the line indicated.
Can someone see where I am making a mistake? Thanks!
+tom
RelayCommand _relayCommand_MoveUp;
public ICommand RelayCommand_MoveUp
{
get
{
if (_relayCommand_MoveUp == null)
{
_relayCommand_MoveUp = new RelayCommand(
(sender, e) => this.Execute_MoveUp(sender, e), **ERROR REPORTED HERE**
(sender, e) => this.CanExecute_MoveUp(sender, e));
return _relayCommand_MoveUp;
}
}
}
private void Execute_MoveUp(object sender, ExecutedRoutedEventArgs e)
{
if (_selectedFolder != null)
{
_selectedFolder.SelectParent();
}
}
private void CanExecute_MoveUp(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = (_selectedFolder != null) && (_selectedFolder.Parent != null);
}
//And from Josh Smith:
public class RelayCommand : ICommand
{
public RelayCommand(Action<object> execute);
public RelayCommand(Action<object> execute, Predicate<object> canExecute);
public event EventHandler CanExecuteChanged;
[DebuggerStepThrough]
public bool CanExecute(object parameter);
public void Execute(object parameter);
}