这些事件是什么时候提出的,它们之间有什么关系?“CommandBinding的CommandManager.CanExecute和CanExecute???
1 回答
The CanExecute
event of a CommandBinding
is fired when the CommandBinding
believes something changed that could affect the state of the command. This is primarily when the user interacts with the UI in some way (mouse moves, clicks, focus changes, etc.), or when a user action causes a PropertyChanged
or CollectionChanged
event. This event does not get fired when your code changes something in the UI, or causes a PropertyChanged
event to fire.
Is there a specific situation you have in mind?
The CommandManager.CanExecute
method is a way to attach a CanExecute
event handler to a UI element, so that when the CanExecute
of the RoutedUICommand
bubbles up the visual tree, it can trigger your CanExecute
event handler. It is just a different way to attach a CanExecute
event to an element for different scenarios, but the end result is the same as adding a CommandBinding
to the CommandBindings
collection of a UIElement
.