Skip to content

Instantly share code, notes, and snippets.

@jakesays-old
Created March 7, 2015 04:03
Show Gist options
  • Save jakesays-old/d45756ef5300873b359e to your computer and use it in GitHub Desktop.
Save jakesays-old/d45756ef5300873b359e to your computer and use it in GitHub Desktop.
SimpleCommand - simple ICommand implementation
public class SimpleCommand : ICommand
{
private readonly Func<bool> _canExecute;
private readonly Action _execute;
public SimpleCommand(Action execute, Func<bool> canExecute = null)
{
_execute = execute;
_canExecute = canExecute;
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void Execute(object parameter)
{
_execute();
}
public bool CanExecute(object parameter)
{
if (_canExecute != null)
{
return _canExecute();
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment