认识WPF中的RoutedEvent Order.

From MSDN, we could get such indications.

In WPF, tunneling events are prefixed by the word Preview by convention. Input events often come in pairs, with one being the bubbling event and one being the tunneling event. For example, the KeyDown event and the PreviewKeyDown event have the same signature, with the former being the bubbling input event and the latter being the tunneling input event. Occasional input events only have a bubbling version, or perhaps only a direct version.

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:

  1. PreviewMouseDown (tunnel) on root element.

  2. PreviewMouseDown (tunnel) on intermediate element #1.

  3. PreviewMouseDown (tunnel) on source element #2.

  4. MouseDown (bubble) on source element #2.

  5. MouseDown (bubble) on intermediate element #1.

  6. MouseDown (bubble) on root element.



posted @ 2007-09-08 19:13  Sean Yao  阅读(590)  评论(2编辑  收藏  举报