comparison SilverlightGlimpse/SilverlightValidation/Commands/RelayCommand.cs @ 69:a0bcd783e612

Latest work
author Steven Hollidge <stevenhollidge@hotmail.com>
date Mon, 23 Apr 2012 11:06:10 +0100
parents
children 86ed4919b126
comparison
equal deleted inserted replaced
68:81337ebf885a 69:a0bcd783e612
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 }