1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-25 06:36:08 +03:00
ProxySU/ProxySU_Core/ViewModels/BaseCommand.cs
2021-02-25 09:59:06 +08:00

42 lines
950 B
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
namespace ProxySU_Core.ViewModels
{
public class BaseCommand : ICommand
{
private readonly Action<object> _execution;
private readonly Func<object, bool> _canExecute;
public BaseCommand(Action<object> execution, Func<object, bool> canExecute = null)
{
_execution = execution;
_canExecute = canExecute;
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
if (_canExecute == null)
{
return true;
}
return _canExecute(parameter);
}
public void Execute(object parameter)
{
if (_execution != null && CanExecute(parameter))
{
_execution.Invoke(parameter);
}
}
}
}