简体   繁体   English

禁用和启用命令源

[英]Command source disabling and enabling

I read all about WPF commanding and i understand the GoF Command Pattern, still thought, i have one question about the process: how does the command target (for example a text box) tell the command source ( a button for instance) that it has changed state (eg. some text inserted into the textbox) so that the source can disable or enable itself or what ever it wishes to do. 我阅读了有关WPF命令的所有内容,并且了解了GoF命令模式,但仍然想到,我对过程有一个疑问:命令目标(例如文本框)如何告诉命令源(例如按钮)更改状态(例如,将一些文本插入到文本框中),以便源可以禁用或启用自身或希望执行的操作。 to put it in another way, how does the command target let the ICommand implementing class (the cut command for example) to trigger it's CanExecuteChangedEvent so that class can in turn let the command source know about state changes. 换句话说,命令目标如何让ICommand实现类(例如cut命令)触发它的CanExecuteChangedEvent,以便该类可以依次使命令源知道状态更改。

There is a class called CommandManager taking care of execution logic. 有一个称为CommandManager的类负责执行逻辑。 You can call CommandManager.InvalidateRequerySuggested method to let system check your CanExecute methods. 您可以调用CommandManager.InvalidateRequerySuggested方法,以使系统检查您的CanExecute方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM