开发者

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

I h开发者_开发技巧ave 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?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜