class CommandHandler : ICommand
{
Action action;
Action<object> action1;
Predicate<object> canexecute;
bool withparam;
bool _canexecute;
public CommandHandler(Action act)
{
action = act;
_canexecute = true;
withparam = false;
}
public CommandHandler(Action<object> act, Predicate<object> canexe)
{
action1 = act;
canexecute = canexe;
withparam = true;
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
if (withparam)
return canexecute(parameter);
else
return _canexecute;
}
public void Execute(object parameter)
{
if (withparam)
action1(parameter);
else
action();
}
}