欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

WPF Customize DelegateCommand

程序员文章站 2022-03-20 08:02:29
public class DelCmd : ICommand { private readonly Predicate _canExecute; private readonly Action _execute; public event EventHandler C ......

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);
}

}