添加项目文件。
This commit is contained in:
29
Commands/EventsCommand.cs
Normal file
29
Commands/EventsCommand.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user