Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1.     class DelegateCommand : ICommand
  2.     {
  3.         protected readonly Predicate<object> _canExecute;
  4.         protected readonly Action<object> _execute;
  5.  
  6.         public event EventHandler CanExecuteChanged;
  7.  
  8.         public DelegateCommand(Action<object> execute) : this(execute, _ => true) { }
  9.  
  10.         public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
  11.         {
  12.             if (execute == null) throw new ArgumentNullException("execute");
  13.             if (canExecute == null) throw new ArgumentNullException("canExecute");
  14.             _execute = execute;
  15.             _canExecute = canExecute;
  16.         }
  17.  
  18.         public bool CanExecute(object parameter) { return _canExecute(parameter); }
  19.  
  20.         public void Execute(object parameter) { _execute(parameter); }
  21.  
  22.         public void RaiseCanExecuteChanged()
  23.         {
  24.             if (CanExecuteChanged != null)
  25.                 CanExecuteChanged.Invoke(this, EventArgs.Empty);
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement