RoutedCommands Executed and PreviewExecuted events

别来无恙 提交于 2019-12-01 05:38:52

I have no idea why that happens (and how it isn't a bug) but here is what was written in the WPF wiki:

There is a particularity about CommandBinding which is extremely interesting and important to know.

The CommandManager uses routed events to notify the different CommandBinding objects that a command execution was invoked (through default gestures, input bindings, explicitly, etc.).

Up to now, this is fairly straightforward. However, what is more important is that CommandBinding will mark the routed event from the CommandManager as handled as soon as a handler gets executed (either PreviewExecuted or Executed).

Finally, even if your handler has a prototype that matches a delegate called ExecutedRoutedEventHandler, the Executed event from the CommandBinding is not a RoutedEvent but a normal CLR event. Setting or leaving the e.Handled flag to false will change nothing.

Therefore, as soon as an Executed or PreviewExecuted handler is invoked, the RoutedCommand will halt its routing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!