问题
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. 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.
回答1:
There is a class called CommandManager taking care of execution logic. You can call CommandManager.InvalidateRequerySuggested method to let system check your CanExecute methods.
来源:https://stackoverflow.com/questions/12662580/command-source-disabling-and-enabling