Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DelegateCommand : ICommand
- {
- protected readonly Predicate<object> _canExecute;
- protected readonly Action<object> _execute;
- public event EventHandler CanExecuteChanged;
- public DelegateCommand(Action<object> execute) : this(execute, _ => true) { }
- public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
- {
- if (execute == null) throw new ArgumentNullException("execute");
- if (canExecute == null) throw new ArgumentNullException("canExecute");
- _execute = execute;
- _canExecute = canExecute;
- }
- public bool CanExecute(object parameter) { return _canExecute(parameter); }
- public void Execute(object parameter) { _execute(parameter); }
- public void RaiseCanExecuteChanged()
- {
- if (CanExecuteChanged != null)
- CanExecuteChanged.Invoke(this, EventArgs.Empty);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement