Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a Trigger on a child to a parent property?

Tags:

I have a TreeView with a ToggleButton ( ExpanderButton ). The togglebutton has a two images ( one for expanded and one when not ). However when I select a TreeViewItem I highligh it with a different color and I'd like to change the color of the images as well ( I have the same ones in the other color ).

Problem is I don't know how to set a trigger property on the ToggleButton to the IsSelected property on the TreeViewItem.

Any Ideas?

like image 931
Ingó Vals Avatar asked Jul 01 '10 14:07

Ingó Vals


1 Answers

Here if anyone else needs this.

<ControlTemplate TargetType="ToggleButton">
                <Image Name="ExpanderImage" Height="24" Width="24" Source="..\Images\Icons\32x32\Blue\Open.png" />
                <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="True">
                        <Setter TargetName="ExpanderImage" Property="Source" Value="..\Images\Icons\32x32\Blue\Close.png" />
                    </Trigger>
                    <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}}" Value="True">
                        <Setter TargetName="ExpanderImage" Property="Source" Value="..\Images\Icons\32x32\Green\Open.png" />
                    </DataTrigger>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding Path=IsChecked, RelativeSource={RelativeSource Self}}" Value="True" />
                            <Condition Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}}" Value="True" />
                        </MultiDataTrigger.Conditions>
                        <Setter TargetName="ExpanderImage" Property="Source" Value="..\Images\Icons\32x32\Green\Close.png" />
                    </MultiDataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
like image 183
Ingó Vals Avatar answered Oct 13 '22 17:10

Ingó Vals