using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace EfemDualUI.Controls.Common { public class RelayCommand : ICommand { private readonly Func canExecute; private readonly Action execute; public RelayCommand(Action execute) : this(execute, null) { } public RelayCommand(Action execute, Func canExecute) { this.execute = execute ?? throw new ArgumentNullException("execute"); this.canExecute = canExecute; } public event EventHandler CanExecuteChanged { add { if (canExecute != null) CommandManager.RequerySuggested += value; } remove { if (canExecute != null) CommandManager.RequerySuggested -= value; } } public Boolean CanExecute(Object parameter) { return canExecute == null ? true : canExecute(parameter); } public void Execute(Object parameter) { execute(parameter); } } }