-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRelayCommand.cs
47 lines (35 loc) · 1.21 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Diagnostics;
using System.Windows.Input;
namespace SubtitlesRunner
{
// taken from http://msdn.microsoft.com/en-us/magazine/dd419663.aspx#id0090030
public class RelayCommand : ICommand
{
#region Fields
private readonly Action<object> _execute; private readonly Predicate<object> _canExecute;
#endregion Fields
#region Constructors
public RelayCommand(Action<object> execute, Predicate<object> canExecute = null)
{
if (execute == null) throw new ArgumentNullException("execute"); _execute = execute; _canExecute = canExecute;
}
#endregion Constructors
public void RaiseCanExecuteChanged()
{
if (CanExecuteChanged != null)
{
CanExecuteChanged(this, EventArgs.Empty);
}
}
#region ICommand Members
[DebuggerStepThrough]
public bool CanExecute(object parameter) { return _canExecute == null || _canExecute(parameter); }
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
_execute(parameter);
}
#endregion ICommand Members
}
}