I have a textbox in a groupbox, both with double click events. When I double click in the textbox both events are triggered.
How do I stop clicks in the textbox from passing through to the groupbox? I've tried putting "e.Handled = true;" at the end of the textbox_DoubleClick event but this makes no difference.
Because WPF uses a "tunneling / bubbling" model of event propagation, most events begin bubbling UP from the bottom of the visual tree. If you want to catch an event on the way down, there are Preview
versions of the events that tunnel downwards. For example:
PreviewMouseDoubleClick
Set e.Handled = true
in there.
In your GroupBox's DoubleClick event you could check the value of e.OriginalSource
and if that value is not the GroupBox
, ignore the event
private void TabItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (e.OriginalSource is GroupBox)
{
// Your code here
}
}
I believe ClickEvents are actually Direct Events, and not Tunneled/Bubbled events, so setting e.Handled
in one won't cancel the other.
Per MSDN Site for MouseDoubleClick
Although this routed event seems to follow a bubbling route through an element tree, it actually is a direct routed event that is raised along the element tree by each UIElement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With