Last active
January 25, 2016 13:40
-
-
Save Konctantin/103200c1994d32402c05 to your computer and use it in GitHub Desktop.
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 RelayCommand<T> : ICommand | |
| { | |
| Action<T> exec; | |
| Predicate<T> canexec; | |
| public RelayCommand(Action<T> exec, Predicate<T> canexec = null) | |
| { | |
| Debug.Assert(exec != null); | |
| this.exec = exec; | |
| this.canexec = canexec; | |
| } | |
| public event EventHandler CanExecuteChanged | |
| { | |
| add { CommandManager.RequerySuggested += value; } | |
| remove { CommandManager.RequerySuggested -= value; } | |
| } | |
| public bool CanExecute(object parameter) => canexec?.Invoke((T)parameter) != false; | |
| public void Execute(object parameter) => exec((T)parameter); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment