BuZz
BuZz

Reputation: 17495

How to process the event on that checkbox only?

In this piece of XAML, I have a groupbox. In its header, there is a checkbox. In its contents, some stuff and another checkbox. What I achieved, is to have the groupbox collapse/expand on unchecking/checking of this checkbox. A side effect that I would like to avoid, is that the same events happen when the checkbox "Compute Power" is checked/unchecked.

I guess I would need to name my header checkbox to then filter the event.

How to do that ? Is that possible ? What do you suggest ?

enter image description here

             <GroupBox  Margin="8,0" BorderBrush="#FF88B1D8" HorizontalAlignment="Stretch" Height="122.3">
                <GroupBox.Resources>
                    <Style TargetType="GroupBox">
                        <Style.Triggers>
                            <EventTrigger RoutedEvent="CheckBox.Unchecked">
                                <BeginStoryboard>                               
                                    <Storyboard>

                                        <DoubleAnimation Storyboard.TargetProperty="Height" Duration="0:0:.2" To="30" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="CheckBox.Checked">
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Height" Duration="0:0:.2" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                        </Style.Triggers>
                    </Style>
                </GroupBox.Resources>
                <GroupBox.Header>
                    <WrapPanel>
                    <CheckBox IsChecked="True" VerticalAlignment="Center" />
                    <Label Content="Skew" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" FontFamily="/WpfControlLibrary1;component/Fonts/#Tahoma" />   
                    </WrapPanel>
                </GroupBox.Header>
                <UniformGrid Columns="2">
                    <Label Content="Spot Intervals"></Label>
                    <TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
                    <Label Content="Hist. references" />
                    <TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
                    <Label Content="Tenors" />
                    <TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
                    <Label Content="Compute 'Power'" />
                    <CheckBox IsChecked="False" VerticalAlignment="Center"/>
                </UniformGrid>
            </GroupBox>

Upvotes: 0

Views: 1680

Answers (1)

RQDQ
RQDQ

Reputation: 15589

As you suggest, one way to attack this is to name your checkboxes:

<GroupBox.Header>
       <WrapPanel>
       <CheckBox x:Name="ExpanderCheckBox" IsChecked="True" VerticalAlignment="Center" />

and specify the SourceName property of of your EventTrigger.

<EventTrigger RoutedEvent="CheckBox.Unchecked" SourceName="ExpanderCheckBox">

Upvotes: 1

Related Questions