WPF Customize DelegateCommand
public class delcmd : icommand
{
private readonly predicate<object> _canexecute;
private readonly action<object> _execute;
public event eventhandler canexecutechanged
{
add { commandmanager.requerysuggested += value; }
remove { commandmanager.requerysuggested -= value; }
}
public delcmd(action<object> execute):this(execute,null)
{
}
public delcmd(action<object> execute,predicate<object> canexecute)
{
_execute = execute;
_canexecute = canexecute;
}
public bool canexecute(object parameter)
{
if(_canexecute==null)
{
return true;
}
return _canexecute(parameter);
}
public void execute(object parameter)
{
_execute(parameter);
}
}
推荐阅读