using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace PersonalFinanceWindow.ViewModel { class RelayCommand : ICommand { public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } private Action methodToExecute; private Func canExecuteEvaluator; public RelayCommand(Action methodToExecute, Func canExecuteEvaluator) { this.methodToExecute = methodToExecute; this.canExecuteEvaluator = canExecuteEvaluator; } public RelayCommand(Action methodToExecute) : this(methodToExecute, null) { } public bool CanExecute(object parameter) { if (this.canExecuteEvaluator == null) { return true; } else { bool result = this.canExecuteEvaluator.Invoke(); return result; } } public void Execute(object parameter) { this.methodToExecute.Invoke(); } } }