Mercurial > silverbladetech
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/delete me/SilverlightValidation/Commands/RelayCommand.cs Sat Apr 21 19:20:28 2012 +0100 @@ -0,0 +1,40 @@ +using System; +using System.Windows.Input; + +namespace SilverlightValidation.Commands +{ + public class RelayCommand : ICommand + { + public event EventHandler CanExecuteChanged = delegate { }; + + readonly Action<object> _execute; + readonly Predicate<object> _canExecute; + + public RelayCommand(Action<object> execute, + Predicate<object> canExecute = null) + { + if (execute == null) throw new ArgumentNullException("execute"); + + _execute = execute; + _canExecute = canExecute; + } + + + public void UpdateCanExecuteCommand() + { + CanExecuteChanged(this, new EventArgs()); + } + + + public bool CanExecute(object parameter) + { + return _canExecute == null || _canExecute(parameter); + } + + + public void Execute(object parameter) + { + _execute(parameter); + } + } +}