mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
40 lines
865 B
C#
40 lines
865 B
C#
#nullable enable
|
|
|
|
using System;
|
|
using System.Windows.Input;
|
|
|
|
namespace Remotely.Agent.Installer.Win.Services;
|
|
|
|
public class RelayCommand : ICommand
|
|
{
|
|
private readonly Action<object> _action;
|
|
|
|
private readonly Predicate<object>? _canExecute;
|
|
|
|
public RelayCommand(Action<object> action, Predicate<object>? canExecute = null)
|
|
{
|
|
_action = action;
|
|
_canExecute = canExecute;
|
|
}
|
|
|
|
public event EventHandler CanExecuteChanged
|
|
{
|
|
add { CommandManager.RequerySuggested += value; }
|
|
remove { CommandManager.RequerySuggested -= value; }
|
|
}
|
|
|
|
public bool CanExecute(object parameter)
|
|
{
|
|
if (_canExecute is null)
|
|
{
|
|
return true;
|
|
}
|
|
return _canExecute.Invoke(parameter);
|
|
}
|
|
|
|
public void Execute(object parameter)
|
|
{
|
|
_action?.Invoke(parameter);
|
|
}
|
|
}
|