using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace CommandPatternSample.Command { internal class RelayCommand : ICommand { private Func _canExecute; private Action _executeAction; public event EventHandler CanExecuteChanged; public RelayCommand(Action executeAction, Func canExeute) { _executeAction = executeAction ?? throw new ArgumentNullException("Execute action is not null"); _canExecute = canExeute; } public RelayCommand(Action executeAction) : this(executeAction, null) { } public bool CanExecute(object parameter) { bool result = _canExecute == null ? true : _canExecute.Invoke(parameter); return result; } public void Execute(object parameter) { _executeAction.Invoke(parameter); } } }