benjaminvr

RelayCommand WPF

Nov 3rd, 2021
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. public class RelayCommand : ICommand {
  2.  
  3.     readonly Action<object> _uittevoeren;
  4.     readonly Predicate<object> _kanUitvoeren;
  5.  
  6.     public RelayCommand(Action<object> execute, Predicate<object> canExecute) {
  7.         if (execute == null)
  8.             throw new ArgumentNullException("Uit te voeren functie kan niet null zijn");
  9.  
  10.         _uittevoeren = execute;
  11.         _kanUitvoeren = canExecute;
  12.     }
  13.  
  14.  
  15.     [DebuggerStepThrough]
  16.     public bool CanExecute(object parameters) {
  17.         return _kanUitvoeren == null ? true : _kanUitvoeren(parameters);
  18.     }
  19.  
  20.     public event EventHandler CanExecuteChanged {
  21.         add { CommandManager.RequerySuggested += value; }
  22.         remove { CommandManager.RequerySuggested -= value; }
  23.     }
  24.  
  25.     public void Execute(object parameters) {
  26.         _uittevoeren(parameters);
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment