How to set a Trigger on a child to a parent property?
Asked Answered
O

1

22

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?

Outsole answered 1/7, 2010 at 14:41 Comment(1)
Well DataBinding with RelativeSource is the correct way I guess. Found out seconds after I posted though I had been searching. Just didn't use the right search phrase.Selah
O
44

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>
Outsole answered 5/7, 2010 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.