I have a problem where I need to combine a DataTrigger
and a PropertyTrigger
into a MultiDataTrigger
to show an Image
in a GridViewColumn
(combined with a TreeView
, it's a custom control I'm using). I experimented and searched some thins on the internet and this is how far I've come:
<Image Width="16"
Height="16"
Stretch="UniformToFill">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Setter Property="Source"
Value="{Binding ScorecardNiveau, Converter={StaticResource ScorecardNiveauToImageConverter}}" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding WpfSettings.IsExpanded}" Value="True" />
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Source}" Value="/folder_closed.png" />
</MultiDataTrigger.Conditions>
<Setter Property="Source" Value="/folder_open.png" />
</MultiDataTrigger>
</Style.Triggers>
</Image.Style>
</Image>
Now, initially, the Image
can have two images, according to the Converter
. Either the folder_open, or another one (not important now). Now what I want is: when the TreeViewNode is expanded (WpfSetting.IsExpanded = true
) and when the Image Source is folder_closed, I want the Image to get the folder_open image. I think I am close with the above code, but it's not really working. The Image
isn't changing at all when I open a TreeViewNode
.
I think I am doing something wrong with the Condition on the RelativeSource=Self
, but I am not sure.
Anyone who can help me please? Thanks in advance.
Of course, more information/code can be provided if needed.
The problem is not with RelativeSource=Self but when you try to compare Source(which is of type ImageSource) to string value ("/folder_closed.png"), it return false
Try the following Condition :
<Condition Binding="{Binding ScorecardNiveau, Converter={StaticResource ScorecardNiveauToImageConverter}}" Value="/folder_closed.png" />