Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

67 righe
1.8 KiB

  1. using System;
  2. using System.Windows.Input;
  3. namespace BPA.UIControl
  4. {
  5. /// <summary>
  6. /// Command
  7. /// </summary>
  8. public class BPACommand : ICommand
  9. {
  10. private readonly Action<object> _execute;
  11. private readonly Func<object, bool> _canExecute;
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="BPACommand"/> class.
  14. /// </summary>
  15. /// <param name="execute">The execute.</param>
  16. public BPACommand(Action<object> execute)
  17. : this(execute, null)
  18. {
  19. }
  20. /// <summary>
  21. /// Initializes a new instance of the <see cref="BPACommand"/> class.
  22. /// </summary>
  23. /// <param name="execute">The execute.</param>
  24. /// <param name="canExecute">The can execute.</param>
  25. public BPACommand(Action<object> execute, Func<object, bool> canExecute)
  26. {
  27. _execute = execute ?? throw new ArgumentNullException(nameof(execute));
  28. _canExecute = canExecute ?? (x => true);
  29. }
  30. /// <inheritdoc/>
  31. public bool CanExecute(object parameter)
  32. {
  33. return _canExecute(parameter);
  34. }
  35. /// <inheritdoc/>
  36. public void Execute(object parameter)
  37. {
  38. _execute(parameter);
  39. }
  40. /// <inheritdoc/>
  41. public event EventHandler CanExecuteChanged
  42. {
  43. add
  44. {
  45. CommandManager.RequerySuggested += value;
  46. }
  47. remove
  48. {
  49. CommandManager.RequerySuggested -= value;
  50. }
  51. }
  52. /// <summary>
  53. /// Refreshes the.
  54. /// </summary>
  55. public void Refresh()
  56. {
  57. CommandManager.InvalidateRequerySuggested();
  58. }
  59. }
  60. }