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