You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

2 years ago
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);
}
}
}