using System; using System.Collections.Generic; using System.Windows.Input; using System.Diagnostics; using System.Text; namespace TradeBlotter.Command { public class RelayCommand : ICommand { readonly Action execute; readonly Predicate canExecute; public RelayCommand(Action execute) : this(execute, null) { } public RelayCommand(Action execute, Predicate canExecute) { if (execute == null) throw new ArgumentNullException("execute"); this.execute = execute; this.canExecute = canExecute; } [DebuggerStepThrough] public bool CanExecute(object parameter) { return canExecute == null ? true : canExecute(parameter); } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public void Execute(object parameter) { execute(parameter); } } }