class DelegateCommand : ICommand { protected readonly Predicate _canExecute; protected readonly Action _execute; public event EventHandler CanExecuteChanged; public DelegateCommand(Action execute) : this(execute, _ => true) { } public DelegateCommand(Action execute, Predicate canExecute) { if (execute == null) throw new ArgumentNullException("execute"); if (canExecute == null) throw new ArgumentNullException("canExecute"); _execute = execute; _canExecute = canExecute; } public bool CanExecute(object parameter) { return _canExecute(parameter); } public void Execute(object parameter) { _execute(parameter); } public void RaiseCanExecuteChanged() { if (CanExecuteChanged != null) CanExecuteChanged.Invoke(this, EventArgs.Empty); } }