// // Copyright 2014 Perforce Software Inc. // using Perforce.Model; using System; using System.Windows.Input; namespace Perforce.Helper { public class DelegateCommand : ICommand { #region Constructors public DelegateCommand(Action execute) : this(execute, null) { } public DelegateCommand(Action execute, Predicate canExecute) { _execute = execute; _canExecute = canExecute; } #endregion #region ICommand Members public event EventHandler CanExecuteChanged; public bool CanExecute(object parameter) { return _canExecute != null ? _canExecute(parameter) : true; } public void Execute(object parameter) { if (_execute != null) _execute(parameter); } public void OnCanExecuteChanged() { CanExecuteChanged(this, EventArgs.Empty); } #endregion private readonly Action _execute = null; private readonly Predicate _canExecute = null; } }