common/Ui/Common.UI/Infrastructure/Command[T].cs
2026-04-23 17:50:07 +02:00

26 lines
687 B
C#

namespace Common.UI.Infrastructure
{
using System;
using System.Windows.Input;
public class Command<T> : ICommand
{
private readonly Action<T> executable;
public Command(Action<T> executable)
=> this.executable = executable;
public event EventHandler CanExecuteChanged
{
add => CommandManager.RequerySuggested += value;
remove => CommandManager.RequerySuggested -= value;
}
public bool CanExecute(object _)
=> this.executable != null;
public void Execute(object parameter)
=> this.executable?.Invoke(parameter is T t ? t : default(T));
}
}