Mercurial > silverbladetech
comparison delete me/SilverlightValidation/Commands/RelayCommand.cs @ 59:3591c26bd63e
MVVMLight added
author | Steven Hollidge <stevenhollidge@hotmail.com> |
---|---|
date | Sat, 21 Apr 2012 19:20:28 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
58:241e2f22ed3c | 59:3591c26bd63e |
---|---|
1 using System; | |
2 using System.Windows.Input; | |
3 | |
4 namespace SilverlightValidation.Commands | |
5 { | |
6 public class RelayCommand : ICommand | |
7 { | |
8 public event EventHandler CanExecuteChanged = delegate { }; | |
9 | |
10 readonly Action<object> _execute; | |
11 readonly Predicate<object> _canExecute; | |
12 | |
13 public RelayCommand(Action<object> execute, | |
14 Predicate<object> canExecute = null) | |
15 { | |
16 if (execute == null) throw new ArgumentNullException("execute"); | |
17 | |
18 _execute = execute; | |
19 _canExecute = canExecute; | |
20 } | |
21 | |
22 | |
23 public void UpdateCanExecuteCommand() | |
24 { | |
25 CanExecuteChanged(this, new EventArgs()); | |
26 } | |
27 | |
28 | |
29 public bool CanExecute(object parameter) | |
30 { | |
31 return _canExecute == null || _canExecute(parameter); | |
32 } | |
33 | |
34 | |
35 public void Execute(object parameter) | |
36 { | |
37 _execute(parameter); | |
38 } | |
39 } | |
40 } |