using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace Example.ViewModels { public class ViewModelCommand : ICommand { //Fields private readonly Action _executeAction; private readonly Predicate _canExecuteAction; public ViewModelCommand(Action executeAction) { _executeAction = executeAction; _canExecuteAction = null; } public ViewModelCommand(Action executeAction, Predicate canExecuteAction) { _executeAction = executeAction; _canExecuteAction = canExecuteAction; } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } //Methods public bool CanExecute(object parameter) { return _canExecuteAction == null ? true : _canExecuteAction(parameter); } public void Execute(object parameter) { _executeAction(parameter); } } }