kidroca

Delegate Command

Dec 16th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. public class DelegateCommand<T> : ICommand
  2. {
  3.     private readonly Action<T> execute;
  4.     private readonly Func<T, bool> canExecute;
  5.  
  6.     public DelegateCommand(Action<T> execute, Func<T, bool> canExecute = null)
  7.     {
  8.         this.execute = execute;
  9.         this.canExecute = canExecute;
  10.     }
  11.  
  12.     public bool CanExecute(object parameter)
  13.     {
  14.         return this.canExecute == null || this.canExecute((T)parameter);
  15.     }
  16.  
  17.     public void Execute(object parameter)
  18.     {
  19.         this.execute((T)parameter);
  20.     }
  21.  
  22.     public event EventHandler CanExecuteChanged;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment