How is a routed event executed? #18589
-
I'm trying to understand how routed events work in Avalonia. Because everything is a little different than in WPF. I make some code. I placed a buttion with an Ellipse in StackPanel In form:
And set events with tunnel strategy:
This works as expected. If you click on the ellipse, you'll see:
But when I set buble strategy:
It works as if it is direct. The event handler of the component where it was called. If you click on the ellipse, you'll see:
When I set direct strategy:
Events are not caught. Why? How does this work? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You should use DevTools to trace events instead: https://docs.avaloniaui.net/docs/guides/implementation-guides/developer-tools#events For the bubbling case, you don't get the event because the For the direct calls, I believe this is because the Avalonia/src/Avalonia.Base/Input/InputElement.cs Lines 153 to 159 in 46d4735 Avalonia/src/Avalonia.Base/Interactivity/EventRoute.cs Lines 77 to 110 in 46d4735 |
Beta Was this translation helpful? Give feedback.
You should use DevTools to trace events instead: https://docs.avaloniaui.net/docs/guides/implementation-guides/developer-tools#events
For the bubbling case, you don't get the event because the
Button
handles the event as part of its Click interaction implementation. This means that all controls above theButton
in the visual tree will not receive the event unless you specifyhandledEventsToo
in theAddHandler
registration.For the direct calls, I believe this is because the
PointerPressedEvent
is registered only to tunnel and bubble. I don't really useDirect
events much. See:Avalonia/src/Avalonia.Base/Input/InputElement.cs
Lines 153 to 159 in 46d4735