79594207

Date: 2025-04-26 17:26:04
Score: 0.5
Natty:
Report link

I've seen A LOT of counterintuitive answers for this, i really wanna clear the confusion for everybody.

I actively searched for this question so i can write the answer for it.

It's simple.

-------------------------------------------------------------------------------------------------------

An example would be helpful, so let's say i have a Grid (ancestor) that contains a Button (descendant).
Each of them can have Preview and no-Preview event for the SAME action (the no-Preview is called bubbling or something but it sounds very stupid to me so i won't call it bubbling).

Let's say the event is MouseRightButtonDown .

Both Grid and Button can catch the MouseRightButtonDown event and do something when they catch it with a method in code-behind (obviously),

they both can also catch the PreviewMouseRightButtonDown event, now we have 4 methods.
Obviously when you do a mouse down at the Button, you'll also hit the Grid, so which method will run first?
The order is Preview -> no-Preview.
In Preview, the order is Ancestor -> Descendant.
In No-preview, the order is Descendant-> Ancestor.

When you set e.Handled = true in any of the 4 methods, it'll prevent the next methods to run (except if you do something with the HandledEventsToo , but i don't know anything about this yet).

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Filler text (0.5): -------------------------------------------------------------------------------------------------------
  • Low reputation (1):
Posted by: Nguyễn Đức Tùng Lâm