Event Routing or A Routed Event is a type of event that is has the ability to invoke handlers not only on on the object that raised the event but also on multiple listeners in an element tree.
There are 2 types of events in WPF
It starts from Target and then bubbles up to the root . Imagine that we have Stack Panel inside Window , a rectangle control inside the StackPanel. If you we fire a bubbled event on a rectangle , it will be first fired on the rectangle , then StackPanel and then on window .
- Most routed events use the bubbling routing .
- Bubbling routed events are used to report input changes from other UI elements.
- All Main events Bubble.
The order of events firing for the controls in Event Tunneling is exactly opposite to the event Bubbling. Do not get confused of the concept. Let me make it very simple and clear. Imagine that we have Stack Panel inside Window , a rectangle control inside the StackPanel. If you we fire a tunneled event on a Window , it will be first fired on the Window, then StackPanel and then on rectangle .
- All the Preview events tunnels down
This is similar to the "routing" that Windows Forms uses for events .These are also called CLR events which we all are used to in .NET environment. Only that event fires.
ex: Mouse Enter
Advantages in RealTime
Routed events support a class handling mechanism in which the class specifies static methods that handles routed events before registered instance handlers can access them. This is concept is useful in control design as custom class can enforce event-driven class behaviors .
In the next post I will discuss practical implementation and how to use event routing in real time applications