Understanding Routing Events: Why I need both, bubble and tunnel events?
Asked Answered
C

2

5

I read this good article about Routed Events, and I understood why we need sometimes bubble Events and sometime we need tunnel Events.

What I didn't understand is, when we use the tunnel Event, why after it is handled or reached to the source element, still the bubble event is launched?

Thanks in advance!

Coddle answered 10/8, 2010 at 15:43 Comment(0)
M
6

The article says that if you put an image on a button, and that image is clicked, the tunnel event for that image will fire. But it is highly likely that you would also want to handle that click as if the button itself was clicked, so a bubble event is also fired which bubbles up to the click event on the button itself (because the button owns the image), so that you can treat the image click like a button click, using the usual event handler for the button.

Mcmurray answered 10/8, 2010 at 15:50 Comment(0)
M
2

I would also like to add that the event for both (Tunnel and Bubble) are different. For tunnel, we use PreviewXXX (eg: PreviewMouseDown) and for bubble event we use XXX (eg: MouseDown) event.

By sequence, Tunnel event gets fired first starting from the root of the application and ends at the source. And the Bubble event is triggered.

It makes perfect sense to have both these events.

Moradabad answered 14/2, 2011 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.