Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I use events all the time, I cheat and use autocomplete in Visual Studio. Object.closing += [tab] button. Put something in the autogenerated function. Some people like to emphasize the "routed" nature of it, and that leads me to believe I'm missing something. Is there more to it? What am I supposed to know about routed events?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Unless I'm missing something, it doesn't sound like you are describing a routed event. Routed events are part of the WPF technology and are described here.

A routed event works where you have a hierarchy of objects in a tree structure--just like you would with a WPF page. Each control is a node on the display tree, with the root node being the Window or Dialog box your XAML file describes. The challenge with this structure is that it is difficult to get and extend the reference of the button you want with the click handler for it. By default the WPF controls will still handle the mouse and keyboard events, but if there are no registered handlers on the object itself, it will pass the event up the hierarchy until something handles it.

The "RoutedEvent" has a reference to the source object and rules for navigating the display tree. That's the "Bubbling", "Direct", or "Tunneling" options described in the article I linked to. Each component knows want to do when it receives a routed event with that rule attached to it.

That is a bit different than declaring an event on a class you created, and then invoking that as needed. Essentially, with that approach, the only event model available is "Direct". The autocomplete that you do in Visual Studio simply generates the handler for you. The WPF structure handles the routing for you, so there's little you have to think about in most cases. It's only when you want to customize how the events behave within the screen that you need to really concern yourself with the intricacies of routed events.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.