Created
March 7, 2015 04:03
-
-
Save jakesays-old/d45756ef5300873b359e to your computer and use it in GitHub Desktop.
SimpleCommand - simple ICommand implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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