Routed Events in WPF

They are the special type of Events that can move up or down the visual tree according to the Routing Strategy. These events can be handled by multiple listeners of the hierarchy or the object that raised the event itself.

Note : You can stop routing by setting e.Handled = true;

Namespace: System.Windows
Assembly: PresentationCore (in PresentationCore.dll)




Routing Strategies

  • Tunneling
  • Bubbling
  • Direct

1. Tunneling

In this type of Routing Strategy, first the event handler of the root element is invoked and then moves down the element tree until it reaches the element that causes the event. So starting from the root element (it can be a page or window) it then travels down through its successive child elements.
These events are also called as ‘Preview Events’.

2. Bubbling

In this type of Routing Strategy, the handler on the source element is invoked and then it moves upwards the element tree, through its successive parents.

3. Direct

It is the most common Routing Strategy in which the event is handled by the element itself which raises the event.