wpf 可通知界面的Delegate命令

来源:互联网 发布:iphone还原网络设置后 编辑:程序博客网 时间:2024/05/16 07:49

publicclassSelfCheckCommand : ICommand

{

publicSelfCheckCommand()

{

}

publicSelfCheckCommand(Action<object> execAction, Func<object,bool> canExecte)

{

ExecuteAction= execAction;

CanExecuteFunc= canExecte;

}

privatebool _canExecuteCache;

publicboolCanExecute(object parameter)

{

if (CanExecuteFunc ==null)

{

returntrue;

}

bool result = CanExecuteFunc(parameter);

if (result != _canExecuteCache)

{

_canExecuteCache= result;

}

return result;

}

publiceventEventHandlerCanExecuteChanged

{

add { CommandManager.RequerySuggested+=value; }

remove { CommandManager.RequerySuggested-=value; }

}

publicvoidExecute(object parameter)

{

if (ExecuteAction !=null)

{

this.ExecuteAction(parameter);

}

}

publicAction<object> ExecuteAction { get;set; }

publicFunc<object,bool> CanExecuteFunc { get;set; }

}

0 0