26 lines
670 B
C#
26 lines
670 B
C#
namespace Common.GUI.ViewModels.Base
|
|
{
|
|
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 o)
|
|
=> this.executable?.Invoke(o is T t ? t : default(T));
|
|
}
|
|
}
|