DelegateCommand.cs 601 B

12345678910111213141516171819
  1. using System;
  2. using System.Windows.Input;
  3. namespace Avalonia.Base.UnitTests.Utilities;
  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. }