pla-01/Life/Misc/DelegateCommand.cs
2019-10-26 19:23:37 +02:00

26 lines
583 B
C#

using System;
using System.Windows.Input;
namespace Life.Misc
{
public class DelegateCommand<T> : ICommand
{
public Action<T> Action { get; set; }
public Predicate<T> Predicate { get; set; }
public bool CanExecute(object parameter)
{
if (Action == null)
return false;
return Predicate?.Invoke((T) parameter) ?? true;
}
public void Execute(object parameter)
{
Action?.Invoke((T)parameter);
}
public event EventHandler CanExecuteChanged;
}
}