using System; using System.Windows.Input; namespace Microsoft.PowerToys.Settings.UI.Helpers { public class RelayCommand : ICommand { private readonly Action execute; private readonly Func canExecute; public event EventHandler CanExecuteChanged; public RelayCommand(Action execute) : this(execute, null) { } public RelayCommand(Action execute, Func canExecute) { this.execute = execute ?? throw new ArgumentNullException(nameof(execute)); this.canExecute = canExecute; } public bool CanExecute(object parameter) => this.canExecute == null || this.canExecute(); public void Execute(object parameter) => this.execute(); public void OnCanExecuteChanged() => this.CanExecuteChanged?.Invoke(this, EventArgs.Empty); } public class RelayCommand : ICommand { private readonly Action execute; private readonly Func canExecute; public event EventHandler CanExecuteChanged; public RelayCommand(Action execute) : this(execute, null) { } public RelayCommand(Action execute, Func canExecute) { this.execute = execute ?? throw new ArgumentNullException(nameof(execute)); this.canExecute = canExecute; } public bool CanExecute(object parameter) => this.canExecute == null || this.canExecute((T)parameter); public void Execute(object parameter) => this.execute((T)parameter); public void OnCanExecuteChanged() => this.CanExecuteChanged?.Invoke(this, EventArgs.Empty); } }