CustomCommand.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Input;
  6. namespace UAS_Web.tool
  7. {
  8. class CustomCommand : ICommand
  9. {
  10. Action _TargetExecuteMethod;
  11. Func<bool> _TargetCanExecuteMethod;
  12. public event EventHandler CanExecuteChanged = delegate { };
  13. public CustomCommand(Action executeMethod)
  14. {
  15. _TargetExecuteMethod = executeMethod;
  16. }
  17. bool ICommand.CanExecute(object parameter)
  18. {
  19. if (_TargetCanExecuteMethod != null)
  20. {
  21. return _TargetCanExecuteMethod();
  22. }
  23. if (_TargetExecuteMethod != null)
  24. {
  25. return true;
  26. }
  27. return false;
  28. }
  29. public void RaiseCanExecuteChanged()
  30. {
  31. CanExecuteChanged(this, EventArgs.Empty);
  32. }
  33. void ICommand.Execute(object parameter)
  34. {
  35. _TargetExecuteMethod?.Invoke();
  36. }
  37. }
  38. }