using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace AutoCat.MVVM { class RelayCommand1 : ICommand where T : new() { private Action action; private Func canExecuteAction; public RelayCommand1(Action action) { this.action = action; this.canExecuteAction = null; } public RelayCommand1(Action action, Func canExecute) { this.action = action; this.canExecuteAction = canExecute; } #region ICommand Members public bool CanExecute(object parameter) { if (canExecuteAction != null) { T param = parameter != null ? (T)parameter : new T(); return canExecuteAction(param); } else { return true; } } public event EventHandler CanExecuteChanged; /* { add => CommandManager.RequerySuggested += value; remove => CommandManager.RequerySuggested -= value; } */ public void Execute(object parameter) { if (parameter != null) { action((T)parameter); } else { action(new T()); } } #endregion } }