Files

40 lines
1.0 KiB
C#
Raw Permalink Normal View History

2023-07-10 17:38:39 +09:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace CommandPatternSample.Command
{
internal class RelayCommand : ICommand
{
private Func<object, bool> _canExecute;
private Action<object> _executeAction;
public event EventHandler CanExecuteChanged;
public RelayCommand(Action<object> executeAction, Func<object, bool> canExeute)
{
_executeAction = executeAction ?? throw new ArgumentNullException("Execute action is not null");
_canExecute = canExeute;
}
public RelayCommand(Action<object> executeAction) : this(executeAction, null)
{
}
public bool CanExecute(object parameter)
{
bool result = _canExecute == null ? true : _canExecute.Invoke(parameter);
return result;
}
public void Execute(object parameter)
{
_executeAction.Invoke(parameter);
}
}
}