图像源上的 wpf 数据触发器 [英] wpf datatrigger on an image source

查看:25
本文介绍了图像源上的 wpf 数据触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设绑定是正确的并且图像文件在它们应该在的地方,有人能发现为什么当触发器评估为真时下面的 xaml 中的图像不会改变吗?

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?

干杯,
贝瑞尔

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

推荐答案

请尝试以下...

  • 在样式上设置 TargetType="{x:Type Image}"
  • 将 setter 的属性更改为 Property="Source"

您的属性路径当前的定义方式是在 Image 上查找名为 Image(不存在)的属性,然后在名为 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.

此外,从顶部的 Image 标签中删除 Source 属性.这将覆盖样式应用的任何内容.您可以将其移动到另一个 DataTrigger 中,也可以像这样将其放入普通的 setter 中:

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>

这篇关于图像源上的 wpf 数据触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆