您的位置:首页 > 其它

WPF中ICommand接口 的一个设计问题

2010-01-27 19:00 555 查看
publicinterfaceICommand
{
//Summary:
//Occurswhenchangesoccurthataffectwhetherornotthecommandshouldexecute.
eventEventHandlerCanExecuteChanged;
boolCanExecute(objectparameter);
voidExecute(objectparameter);
}
//Definesanobjectthatknowshowtoinvokeacommand.
publicinterfaceICommandSource
{
//Summary:
//Getsthecommandthatwillbeexecutedwhenthecommandsourceisinvoked.
ICommandCommand{get;}
objectCommandParameter{get;}
IInputElementCommandTarget{get;}
}
MSDN:
Normally,acommandsourcewilllistentotheCanExecuteChangedeventonthecommand.Thisinformsthecommandsourcewhenconditionschangeonthecommandtarget,suchaslossofkeyboardfocus.ThecommandsourcecanthenquerythecommandusingtheCanExecutemethod.

按照MSDN中的解释,当CanExecuteChanged事件发生时,ICommandSource会调用ICommand的CanExecute方法来检测是否可以执行命令。如果是这样,这里的这个事件名取为:类似“CanExecuteConditionChanged”不是更好吗?

因为CanExecuteChanged发生,使用者的第一感觉就是CanExecute从false变到true或者由true变到false了。

关于这个设计问题,我想不出原因,所以希望高人解释下。:)

另外,还有一个小问题,MSDN中说到:

IntheWindowsPresentationFoundation(WPF)commandingsystem,theCommandTargetpropertyonaICommandSourceisonlyapplicablewhentheICommandisaRoutedCommand.IftheCommandTargetissetonaICommandSourceandthecorrespondingcommandisnotaRoutedCommand,thecommandtargetisignored.
那么,设计这个属性会不会有点多余?虽然我觉得加上也是好的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: