How do I stop a routed event from triggering on specific places in XAML?
- by cfouche
I have the following situation:
A stackpanel contains a number of elements, including some that are contained in a GroupBox. So something like this:
<StackPanel x:Name="stackpanel" Background="White">
<TextBlock Text="TextBlock"/>
<TextBlock Text="Another TextBlock"/>
<!--plus a load of other elements and controls-->
<GroupBox Header="GroupBoxHeader">
<TextBlock Text="Text inside GroupBox"/>
</GroupBox>
</StackPanel>
I want a MouseDown in the stackpanel to trigger some Storyboard, so I've added an EventTrigger, like this:
<EventTrigger RoutedEvent="Mouse.MouseDown" SourceName="stackpanel">
<BeginStoryboard Storyboard="{StaticResource OnMouseDown1}"/>
</EventTrigger>
This is almost right, but the thing is - I don't want the MouseDown to be picked up by the GroupBox's header or border, only by its content. In other words, I want the Storyboard to begin when someone does a mousedown on anything inside the StackPanel, except GroupBox headers and borders.
Is there some way of doing this? (I've tried setting e.Handled to true on the GroupBox, but then its content doesn't pick up the mousedown anymore either.)