-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRelayCommand.cs
27 lines (21 loc) · 953 Bytes
/
RelayCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System.Windows.Input;
namespace ChristmasClockController
{
public class RelayCommand : ICommand {
private readonly System.Action<object?> _execute;
private readonly System.Func<bool> _canExecute;
public RelayCommand(System.Action execute, System.Func<bool> canExecute) {
_execute = _=>execute();
_canExecute = canExecute;
}
public RelayCommand(System.Action<object?> execute, System.Func<bool> canExecute) {
_execute = execute;
_canExecute = canExecute;
}
public RelayCommand(System.Action execute) : this(execute, () => true) { }
public RelayCommand(System.Action<object?> execute) : this(execute, () => true) { }
public bool CanExecute(object? parameter) => _canExecute();
public void Execute(object? parameter) => _execute(parameter);
public event System.EventHandler? CanExecuteChanged;
}
}