UI 事件是如何在 WPF 中生成的?

How are UI events generated in WPF?

我正在尝试了解 UI 相关的 RoutedEvents 在 WPF 中是如何生成的。

例如,在控件上按下鼠标左键如何启动 PreviewMouseDown 的隧道?

我自己找不到明确的答案。我的直觉是 window(例如 WM_MOUSEFIRST)收到的消息被处理并因此引发事件,但这只是我的猜测。

最终它 必须 WM_MOUSEFIRST 和类似的 Windows 事件触发 WPF 中的操作。毫无疑问。这就是 Windows 的工作原理。

在 WPF 内部,这里使用 EventManager and GlobalEventManager to handle events. A Window and all subsequent base classes registers itself at the EventManager (like Window and FrameworkElement

EventManager 处理实际事件并负责路由。

实际的鼠标事件由HwndMouseInputProvider and some Window events by Window itself处理。