The following examples show how bubbling and tunneling works in a routed event, and how to handle them using code.
Routed event introduces bubbling and tunneling routing strategy.
In bubbling routing strategy, the event handlers on the event source are invoked. The routed event then routes to successive parent elements until reaching the element tree root. Most routed events use the bubbling routing strategy.
The following example shows how to handle the KeyDown routed event, which is a bubbling event.
In tunneling routing strategy, the event handlers at the element tree root are initially invoked. The routed event then travels a route through successive child elements along the route, towards the node element that is the routed event source (the element that raised the routed event). Tunneling events are also sometimes referred to as Preview events, because of a naming convention that is used for the pairs.
The following example shows how to handle the PreviewKeyDown routed event, which is a tunneling event.