using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace PSPiZK { public class MvvmCommand : ICommand { private Action execute; private Func canExecute; public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public MvvmCommand(Action execute, Func canExecute = null) { if (execute == null) throw new ArgumentNullException(nameof(execute)); else this.execute = execute; this.canExecute = canExecute; } public bool CanExecute(object parameter) { if (canExecute == null) return true; else return canExecute(parameter); } public void Execute(object parameter) { execute(parameter); } } }