DelegatedCommand.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Input;
  6. namespace Aitex.UI.RecipeEditor
  7. {
  8. public class DelegatedCommand : ICommand
  9. {
  10. public DelegatedCommand(Predicate<object> CanExecute, Action<object> Execute)
  11. {
  12. _canExecute = CanExecute;
  13. _execute = Execute;
  14. }
  15. Predicate<object> _canExecute;
  16. Action<object> _execute;
  17. /// <summary>
  18. ///
  19. /// </summary>
  20. /// <param name="parameter"></param>
  21. /// <returns></returns>
  22. public bool CanExecute(object parameter)
  23. {
  24. if (_canExecute != null)
  25. return _canExecute.Invoke(parameter);
  26. return true;
  27. }
  28. public event EventHandler CanExecuteChanged;
  29. public void Execute(object parameter)
  30. {
  31. if (_execute != null)
  32. _execute.Invoke(parameter);
  33. }
  34. public void RaiseCanExecuteChanged()
  35. {
  36. if (CanExecuteChanged != null)
  37. CanExecuteChanged(this, EventArgs.Empty);
  38. }
  39. }
  40. }