Advertisement
Guest User

Untitled

a guest
Apr 13th, 2020
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Input;
  7.  
  8. namespace WPF_Training
  9. {
  10.     public class DelegateCommand : ICommand
  11.     {
  12.         private readonly Action<object> executeMethod = null;
  13.         private readonly Func<object, bool> canExecuteMethod = null;
  14.  
  15.         public event EventHandler CanExecuteChanged
  16.         {
  17.             add { return; }
  18.             remove { return; }
  19.         }
  20.  
  21.         public DelegateCommand(Action<object> executeMethod, Func<object, bool> canExecuteMethod)
  22.         {
  23.             this.executeMethod = executeMethod;
  24.             this.canExecuteMethod = canExecuteMethod;
  25.         }
  26.  
  27.         public bool CanExecute(object parameter)
  28.         {
  29.             if (canExecuteMethod == null) return true;
  30.             return this.canExecuteMethod(parameter);
  31.         }
  32.  
  33.         public void Execute(object parameter)
  34.         {
  35.             if (executeMethod == null) return;
  36.             this.executeMethod(parameter);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement