DelegateCommand.cs 592 B

12345678910111213141516171819
  1. using System;
  2. using System.Windows.Input;
  3. namespace IntegrationTestApp;
  4. internal class DelegateCommand : ICommand
  5. {
  6. private readonly Action _action;
  7. private readonly Func<object?, bool> _canExecute;
  8. public DelegateCommand(Action action, Func<object?, bool>? canExecute = default)
  9. {
  10. _action = action;
  11. _canExecute = canExecute ?? new(_ => true);
  12. }
  13. public event EventHandler? CanExecuteChanged { add { } remove { } }
  14. public bool CanExecute(object? parameter) => _canExecute(parameter);
  15. public void Execute(object? parameter) => _action();
  16. }