45 lines
1019 B
C#
45 lines
1019 B
C#
namespace FahzeugWPF;
|
|
|
|
using System.Diagnostics;
|
|
using System.Windows.Input;
|
|
|
|
public class RelayCommand : ICommand
|
|
{
|
|
readonly Action<object> _execute = null;
|
|
readonly Predicate<object> _canExecute = null;
|
|
|
|
public RelayCommand(Action<object> execute)
|
|
: this(execute, null)
|
|
{
|
|
// Nothing to do
|
|
}
|
|
|
|
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
|
|
{
|
|
if (execute == null)
|
|
{
|
|
throw new ArgumentNullException("execute");
|
|
}
|
|
|
|
this._execute = execute;
|
|
this._canExecute = canExecute;
|
|
}
|
|
|
|
[DebuggerStepThrough]
|
|
public bool CanExecute(object parameter)
|
|
{
|
|
return _canExecute == null ? true : _canExecute(parameter);
|
|
}
|
|
|
|
public event EventHandler CanExecuteChanged
|
|
{
|
|
add { CommandManager.RequerySuggested += value; }
|
|
remove { CommandManager.RequerySuggested -= value; }
|
|
}
|
|
|
|
public void Execute(object parameter)
|
|
{
|
|
_execute(parameter);
|
|
}
|
|
}
|