using System; using System.Windows.Input; namespace Core.Gui.Commands { /// /// Defines a simple command that executes an . /// public class RelayCommand : ICommand { private readonly Action action; private readonly Func canExecute; public event EventHandler CanExecuteChanged; /// /// Creates a new instance of . /// /// The action to execute. /// Thrown when is null. public RelayCommand(Action action) : this(action, o => true) {} /// /// Creates a new instance of . /// /// The action to execute. /// The function that determines whether command can execute. /// Thrown when is null. public RelayCommand(Action action, Func canExecute) { if (action == null) { throw new ArgumentNullException(nameof(action)); } if (canExecute == null) { throw new ArgumentNullException(nameof(canExecute)); } this.action = action; this.canExecute = canExecute; } public bool CanExecute(object parameter) { return canExecute(parameter); } public void Execute(object parameter) { action(parameter); } } }