forked from WolvenKit/WolvenKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DelegateCommand.cs
38 lines (32 loc) · 982 Bytes
/
DelegateCommand.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
37
38
using System;
using System.Windows.Input;
namespace WolvenKit.WolvenKit.W3SavegameEditor
{
public class DelegateCommand : ICommand
{
private readonly Action<object> _execute;
private readonly Predicate<object> _canExecute;
public DelegateCommand(Action<object> execute, Predicate<object> canExecute = null)
{
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return _canExecute == null || _canExecute(parameter);
}
public void Execute(object parameter)
{
if (_execute != null)
{
_execute(parameter);
}
}
public event EventHandler CanExecuteChanged;
protected virtual void OnCanExecuteChanged()
{
var handler = CanExecuteChanged;
if (handler != null) handler(this, EventArgs.Empty);
}
}
}