26 lines
583 B
C#
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;
|
|
}
|
|
} |