0

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.

Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
Jelle Capenberghs
  • 794
  • 2
  • 14
  • 30

1 Answers1

1

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" />
Avani Vadera
  • 526
  • 3
  • 7
  • I tried it and it's still not working, although it makes a lot of sense comparing the return value of the converter. – Jelle Capenberghs Mar 01 '12 at 10:56
  • I think the problem is with the WpfSettings.IsExpanded property. When I debug it with a MultiValueConverter, the IsExpanded property has "UnsetDependencyProperty" as value, maybe the same when the trigger is called. – Jelle Capenberghs Mar 01 '12 at 11:01
  • Yes could be. I tried a similar test code with IsExpanded as true/false and it worked as expected – Avani Vadera Mar 01 '12 at 11:13
  • Okay, then I will need to find another solution. Thank you! Will mark as answered because the solution given should answer the question :) – Jelle Capenberghs Mar 01 '12 at 11:42