32 lines
913 B
C#
32 lines
913 B
C#
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<Task> _execute;
|
|
private readonly Func<bool> _canExecute;
|
|
|
|
public RelayCommand(Func<Task> execute, Func<bool> 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();
|
|
}
|
|
}
|