using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace ProgressBarMVVMSample.Command { internal class DelegateCommand : ICommand { private readonly Action _execute; private readonly Predicate _canExecute; public event EventHandler CanExecuteChanged; //{ // add { CommandManager.RequerySuggested += value; } // remove { CommandManager.RequerySuggested -= value; } //} public DelegateCommand(Action execute, Predicate canExecute) { _execute = execute; _canExecute = canExecute; } public DelegateCommand(Action execute) : this(execute, null) { } public DelegateCommand(Action execute, bool b) : this(execute, null) { } public bool CanExecute(object parameter) { return _canExecute == null ? true : _canExecute(parameter); } public void Execute(object parameter) { _execute.Invoke(parameter); } } }