using System; using System.Windows.Input; namespace CADSnoop.Model { public class RelayCommand : ICommand { readonly Action _execute; readonly Func _canExecute; public RelayCommand(Action execute, Func canExecute) { if (execute == null) throw new NullReferenceException("execute"); _execute = execute; _canExecute = canExecute; } public RelayCommand(Action execute) : this(execute, null) { } public event EventHandler CanExecuteChanged { add => CommandManager.RequerySuggested += value; remove => CommandManager.RequerySuggested -= value; } public bool CanExecute(object parameter) { return _canExecute == null ? true : _canExecute(); } public void Execute(object parameter) { _execute.Invoke(); } } }