Manage routed events in WPF

May include but is not limited to: tunneling vs. bubbling events, handling and cancelling events

OK, this is probably more interesting than building an animation, so let’s begin! I guess every one of us got this far is fairly familiar with events. They are everywhere (especially if you use ASP.NET WebForms); but what is that ugly routed word before them? It’s simpler than you might imagine first. A routed event is an event that can be catch and (or) handled on an element that didn’t fire it (but there should be some relation). Imagine a click to a button. You can handle that click on the button level, but if a button is inside a grid, and then you can handle the click on the grid level, or even at the window level. I used the word handle, but it’s a little misleading. It suggests that the event is finished, gone for good after you make it trigger some event handler. Now this is not necessarily the case, you can handle a routed event multiple times in multiple places.

The previous paragraph became too long, so I start a new one. There are two types of routed events (I think everything starts to have two types) tunneling events which goes down to the hierarchy (like any tunnel) and is start from the Window (or the topmost container). The other type is bubbling event, which goes up in the hierarchy like a bubble (but it’s not falling back sometimes). Continue reading “Manage routed events in WPF”