-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRelayCommand.cs
36 lines (27 loc) · 879 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
28
29
30
31
32
33
34
35
36
using System;
using System.Linq;
using System.Windows.Input;
namespace csv_merge
{
public class RelayCommand : ICommand
{
protected Func<bool> CanExecuteFunc { get; }
protected Action ExecuteFunc { get; }
public RelayCommand(Action executeFunc, Func<bool> canExecuteFunc)
{
CanExecuteFunc = canExecuteFunc;
ExecuteFunc = executeFunc;
}
public bool CanExecute(object parameter) => CanExecuteFunc();
public void Execute(object parameter) => ExecuteFunc();
public event EventHandler CanExecuteChanged;
protected virtual void OnCanExecuteChanged(object sender, EventArgs e)
{
CanExecuteChanged?.Invoke(sender, e);
}
public void CanExecuteChange()
{
OnCanExecuteChanged(this, EventArgs.Empty);
}
}
}