-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelayCommand.cs
More file actions
33 lines (28 loc) · 868 Bytes
/
RelayCommand.cs
File metadata and controls
33 lines (28 loc) · 868 Bytes
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
using System;
using System.Windows.Input;
namespace EmbeddedRecordCreator
{
public class RelayCommand : ICommand
{
private readonly Func<object?, bool>? canExecute;
private readonly Action<object?> execute;
public RelayCommand(Action<object?> execute, Func<object?, bool>? canExecute = null)
{
this.execute = execute;
this.canExecute = canExecute;
}
public event EventHandler? CanExecuteChanged
{
add => CommandManager.RequerySuggested += value;
remove => CommandManager.RequerySuggested -= value;
}
public bool CanExecute(object? parameter)
{
return canExecute == null || canExecute(parameter);
}
public void Execute(object? parameter)
{
execute(parameter);
}
}
}