#580 – Events in WPF are Routed

In Windows Forms, controls make use of traditional .NET events to notify a user that something interesting happened in the control.  When a user clicks on a button, the corresponding Button object will raise a Click event.  You can then define an event handler that does something as a response to the click.

In WPF, events are routed, meaning that the originating control will raise the event but the event will also be passed on to other controls and they will also raise the event.  More specifically, events are passed up (bubbled) or down (tunneled) the logical and visual trees in WPF.

For example, if a StackPanel contains a Button and the user clicks on the button, the Button object will raise a Click event and then the containing StackPanel will also raise a Click event.  The Click event is a bubbling eventso it bubbles up the logical tree.

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.