29 lines
878 B
C#
29 lines
878 B
C#
using System.Windows.Input;
|
|
|
|
namespace YwxApp.AiChat.Commands
|
|
{
|
|
|
|
public class EventsCommand<T> : ICommand
|
|
{
|
|
private readonly Action<T> _execute;
|
|
private readonly Func<T, bool> _canExecute;
|
|
public EventsCommand(Action<T> execute, Func<T, bool> canExecute = null)
|
|
{
|
|
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
|
_canExecute = canExecute;
|
|
}
|
|
public bool CanExecute(object parameter)
|
|
{
|
|
return _canExecute?.Invoke((T)parameter) ?? true;
|
|
}
|
|
public void Execute(object parameter)
|
|
{
|
|
_execute((T)parameter);
|
|
}
|
|
public event EventHandler CanExecuteChanged
|
|
{
|
|
add { CommandManager.RequerySuggested += value; }
|
|
remove { CommandManager.RequerySuggested -= value; }
|
|
}
|
|
}
|
|
} |