comparison SilverlightValidation/SilverlightValidation.PL/Commands/RelayCommand.cs @ 96:188f8b366e87

Unit test project correctly setup as normal class library DLL.
author stevenhollidge <stevenhollidge@hotmail.com>
date Sat, 05 May 2012 13:29:56 +0100
parents SilverlightValidation/SilverlightValidation/Commands/RelayCommand.cs@241e2f22ed3c
children
comparison
equal deleted inserted replaced
95:64e9903703a3 96:188f8b366e87
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 }