认识WPF中的RoutedEvent Order.
Input events that come in pairs are implemented such that a single user action from input such as a mouse button press will raise both events of the pair in sequence. First, the tunneling event is raised and travels its route. Then the bubbling event is raised and travels its route. The two events will literally share the same event data instance. Listeners with handlers for the tunneling event have first opportunity to mark the event handled. If an element along the tunneling route marked the event as handled, the already-handled event data is sent for the bubbling event, and typical handlers attached for the equivalent bubbling events will not be invoked. To outward appearances it will be as if the handled bubbling event had not even been raised.
To illustrate how input event processing works, consider the following input event example. In the following tree illustration, leaf element #2
is the source of both a PreviewMouseDown and then a MouseDown event.
The order of event processing is as follows:
-
PreviewMouseDown (tunnel) on root element.
-
PreviewMouseDown (tunnel) on intermediate element #1.
-
PreviewMouseDown (tunnel) on source element #2.
-
MouseDown (bubble) on source element #2.
-
MouseDown (bubble) on intermediate element #1.
-
MouseDown (bubble) on root element.