using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace PersonalMVVMToolkit { public class RelayCommand : ICommand { #region Fields private readonly Action execute; private readonly Func canExecute; #endregion #region Properties public event EventHandler? CanExecuteChanged; public bool CanExecute(object? parameter) { T param = (T)parameter; return canExecute(param); } public void Execute(object? parameter) { T param = (T)parameter; execute(param); } public void RefreshCommand() => CanExecuteChanged?.Invoke(this, EventArgs.Empty); #endregion #region Constructor public RelayCommand(Action execute, Func canExecute = null) { this.execute = execute; this.canExecute = canExecute ?? (t => true); } #endregion } public class RelayCommand : RelayCommand { #region Constructor public RelayCommand(Action execute, Func canExecute = null) : base(new Action (o => execute()), canExecute != null ? new Func(o => canExecute()) : null) { } #endregion } }