在 WPF 中,对于大多数 UI 事件,我们也有 PreviewX
事件。为什么通用应用程序中没有这样的东西?难道事件系统和WPF的事件系统有根本的不同,不需要它吗?
最佳答案
找到答案了,系统已经从冒泡和隧道变成了。现在它可以与路由事件一起使用。更多信息可查询here 。以下是重要摘录:
Earlier we said that setting Handled to true prevents most handlers from being called. But the AddHandler method provides a technique where you can attach a handler that is always invoked for the route, even if some other handler earlier in the route has set Handled to true in the shared event data.
因此,您不需要像往常一样添加事件处理程序,而是需要调用 AddHandler
来添加“预览”处理程序。
需要注意的事情:文档并没有说这些特殊处理程序在常规处理程序之前执行,因此它与 PreviewX
方法不完全相同。
关于xaml - 为什么 UWP 中没有预览事件处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32088708/