mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-12 08:48:30 +00:00
51 lines
1013 B
C#
51 lines
1013 B
C#
using System;
|
|
using System.Windows.Input;
|
|
|
|
namespace Example_Ambilight_full.TakeAsIs.UI
|
|
{
|
|
public class ActionCommand : ICommand
|
|
{
|
|
#region Properties & Fields
|
|
|
|
private readonly Func<bool> _canExecute;
|
|
private readonly Action _command;
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public ActionCommand(Action command, Func<bool> canExecute = null)
|
|
{
|
|
this._command = command;
|
|
this._canExecute = canExecute;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
public bool CanExecute(object parameter)
|
|
{
|
|
return _canExecute?.Invoke() ?? true;
|
|
}
|
|
|
|
public void Execute(object parameter)
|
|
{
|
|
_command?.Invoke();
|
|
}
|
|
|
|
public void RaiseCanExecuteChanged()
|
|
{
|
|
CanExecuteChanged?.Invoke(this, new EventArgs());
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
public event EventHandler CanExecuteChanged;
|
|
|
|
#endregion
|
|
}
|
|
}
|