views:

347

answers:

2

Assuming the binding is right and the image files are where they shuld be, can anyone spot why the image in the xaml below won't change when the trigger evaluates to true?

Cheers,
Berryl

            <Image Source="..\..\Images\OK.png" Grid.Column="2" Stretch="None">
                <Image.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding TimeSheet, Converter={StaticResource overQuotaConv}}" Value="True">
                                <Setter Property="Image.Source" Value="..\..\Images\Error.png"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Image.Style>
            </Image>
+2  A: 

Try the following...

  • Set the TargetType="{x:Type Image}" on the Style
  • Change the setter's Property to Property="Source"

The way your property path is currently defined, it's looking for a property on Image called Image (which doesn't exist) then within that something called Source.

Additionally, remove the Source attribute from the Image tag at the top. This will override whatever is applied by the style. You can move it to another DataTrigger or you can put it in a normal setter like so:

<Image Grid.Column="2" Stretch="None">
    <Image.Style>
        <Style TargetType="{x:Type Image}">
            <Setter Property="Source" Value="..\..\Images\OK.png" />
            <Style.Triggers>
                <DataTrigger Value="True" Binding="{Binding TimeSheet, Converter={StaticResource overQuotaConv}}">
                    <Setter Property="Source" Value="..\..\Images\Error.png"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Image.Style>
</Image>

Your timing is interesting. I am just about to post something on my blog about a control that does something very similar to this but in a much more concise syntax.

Josh Einstein
suh-weetthis stuff is coming in byte sized bits to me so far. thanks!
Berryl
A: 

Josh Einstein's answer helped me find the fix in my code.

In my particular case I had set a default value for the Source property and it was somehow short-circuiting the trigger's for the style.

...sorry stack overflow I would have just voted up but I cannot do that yet.

TWood