根据布尔无需转换器绑定Image.Source? [英] Bind Image.Source according to Boolean without a converter?

查看:130
本文介绍了根据布尔无需转换器绑定Image.Source?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有结合到布尔图象和具有图象的源依赖于布尔值

I want to have an image bound to a boolean and have the source of the image to depend on the boolean value

即。真正来源=此搜索假源=IMAGE2

i.e. true source="image1" false source="image2"

我想知道是否有办法做到这一点的内联而不需要一个转换器。

I was wondering if there is a way to do it inline without need for a converter.

推荐答案

您可以创建它使用一个DataTrigger交换取决于约束力的图像源图像的样式。在本实施例依赖于简单地称为价值的布尔值的图像的变化。

You can create a style on the Image which uses a DataTrigger to swap the image source depending on a binding. In this example the image changes depending on the value of a boolean called simply "Value".

    <Image Width="16">
        <Image.Style>
            <Style TargetType="{x:Type Image}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Value}" Value="False">
                        <Setter Property="Source" Value="Resources/image1.png"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Value}" Value="True">
                        <Setter Property="Source" Value="Resources/image2.png"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Image.Style>
    </Image>

这篇关于根据布尔无需转换器绑定Image.Source?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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