SHARE
TWEET

Untitled

a guest Sep 13th, 2017 119 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top