如何设置一个触发孩子父母的财产? [英] How to set a Trigger on a child to a parent property?
本文介绍了如何设置一个触发孩子父母的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个切换按钮(ExpanderButton)一个TreeView。切换按钮有两个图像(一个用于扩展和一个不用时)。然而,当我选择一个树型视图我用不同的颜色highligh它,我想改变图像的颜色,以及(我有其他颜色相同的)。
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 ).
但问题是我不知道如何在切换按钮设置触发属性的树型视图IsSelected属性。
Problem is I don't know how to set a trigger property on the ToggleButton to the IsSelected property on the TreeViewItem.
任何想法?
推荐答案
下面是否有人需要这个。
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>
这篇关于如何设置一个触发孩子父母的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文