using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace bububu { class DelegateCommand : ICommand { Action execute; Func canExecute; public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public bool CanExecute(object parameter) { if(canExecute != null) { return canExecute(parameter); } return true; } public void Execute(object parameter) { if (execute != null) { execute(parameter); } } public DelegateCommand(Action executeAction) : this(executeAction, null) { } public DelegateCommand(Action executeAction, Func canExecuteFunc) { canExecute = canExecuteFunc; execute = executeAction; } } }