mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
41 lines
979 B
C#
41 lines
979 B
C#
using System;
|
|
using System.Windows.Input;
|
|
|
|
namespace Artemis.UI.Utilities
|
|
{
|
|
public class DelegateCommand : ICommand
|
|
{
|
|
private readonly Predicate<object> _canExecute;
|
|
private readonly Action<object> _execute;
|
|
|
|
public DelegateCommand(Action<object> execute) : this(execute, null)
|
|
{
|
|
}
|
|
|
|
public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
|
|
{
|
|
_execute = execute;
|
|
_canExecute = canExecute;
|
|
}
|
|
|
|
public event EventHandler CanExecuteChanged;
|
|
|
|
public bool CanExecute(object parameter)
|
|
{
|
|
if (_canExecute == null)
|
|
return true;
|
|
|
|
return _canExecute(parameter);
|
|
}
|
|
|
|
public void Execute(object parameter)
|
|
{
|
|
_execute(parameter);
|
|
}
|
|
|
|
public void RaiseCanExecuteChanged()
|
|
{
|
|
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
} |