using System; using System.Windows.Input; namespace SignalsMVVM.HelperClasses { public class RelayCommand : ICommand { protected Action _execute; protected Func _canExecute; protected RelayCommand() { } public RelayCommand(Action execute, Func canExecute) { if (execute == null) throw new ArgumentNullException(nameof(execute)); _execute = execute; _canExecute = canExecute ?? (p => true); } public RelayCommand(Action execute) : this(execute, (Func)null) { } public RelayCommand(Action execute, Func canExecute) : this(execute, p => canExecute()) { } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public void Execute(object parameter) => _execute((T)parameter); public bool CanExecute(object parameter) => _canExecute((T)parameter); } public class RelayCommand : RelayCommand { public RelayCommand(Action execute, Func canExecute) : base(execute, canExecute) { } public RelayCommand(Action execute) : base(p => execute()) { } public RelayCommand(Action execute, Func canExecute) : base(p => execute(), p => canExecute()) { } public RelayCommand(Action execute) : base(execute) { } public RelayCommand(Action execute, Func canExecute) : base(execute, canExecute) { } } }