mirror of
https://github.com/MaxiFan/TunnelX.git
synced 2026-05-18 05:24:36 +03:00
24 lines
702 B
C#
24 lines
702 B
C#
using System.Windows.Input;
|
|
|
|
namespace AppTunnel.ViewModels;
|
|
|
|
public class RelayCommand : ICommand
|
|
{
|
|
private readonly Action<object?> _execute;
|
|
private readonly Predicate<object?>? _canExecute;
|
|
|
|
public RelayCommand(Action<object?> execute, Predicate<object?>? canExecute = null)
|
|
{
|
|
_execute = execute;
|
|
_canExecute = canExecute;
|
|
}
|
|
|
|
public bool CanExecute(object? parameter) => _canExecute?.Invoke(parameter) ?? true;
|
|
public void Execute(object? parameter) => _execute(parameter);
|
|
public event EventHandler? CanExecuteChanged
|
|
{
|
|
add => CommandManager.RequerySuggested += value;
|
|
remove => CommandManager.RequerySuggested -= value;
|
|
}
|
|
}
|