using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace WpfApp1TRC20.ViewModels { public class RelayCommand : ICommand { private readonly Func _execute; private readonly Func _canExecute; public RelayCommand(Func execute, Func canExecute = null) { _execute = execute ?? throw new ArgumentNullException(nameof(execute)); _canExecute = canExecute; } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public bool CanExecute(object parameter) => _canExecute?.Invoke() ?? true; public async void Execute(object parameter) => await _execute(); } }