Mercurial > silverbladetech
view SilverlightValidation/SilverlightValidation.PL/Commands/RelayCommand.cs @ 114:e51a6af1c98d
working version
author | adminsh@apollo |
---|---|
date | Sat, 19 May 2012 16:53:34 +0100 |
parents | 188f8b366e87 |
children |
line wrap: on
line source
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); } } }