How do I stop a routed event from triggering on specific places in XAML?

Posted by cfouche on Stack Overflow See other posts from Stack Overflow or by cfouche
Published on 2010-03-12T08:30:40Z Indexed on 2010/03/12 8:37 UTC
Read the original article Hit count: 266

Filed under:
|
|
|

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.)

© Stack Overflow or respective owner

Related posts about xaml

Related posts about beginner