wpf - XAML代码重用( bool 值到图像绑定(bind))

标签 wpf xaml binding

我希望能够重用此 XAML,而不是制作副本并更改绑定(bind)路径。有什么解决办法吗?

我想在数据网格中显示 bool 列的勾号或十字。

<Image>
    <Image.Style>
        <Style TargetType="{x:Type Image}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Status}" Value="False">
                    <Setter Property="Source" Value="Images/cross.png"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="True">
                    <Setter Property="Source" Value="Images/check.png"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
   </Image.Style>
</Image>

最佳答案

您可以编写一个简单的 Bool 到 ImageSource 转换器,如果转换后的值为 false,则返回“false.png”,如果值为 true,则返回另一个图像。

关于wpf - XAML代码重用( bool 值到图像绑定(bind)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3508496/

相关文章:

python - 使用 SQLite 和 Python 读取数据库 : Incorrect number of binding supplied

wpf - 绑定(bind)源 vs x :Static

c# - 如何使用 DataTable 作为 DataGrid 的 ItemsSource

控件模板中的 WPF 嵌套绑定(bind)

c# - 如何在 C# 代码中设置默认样式(而不是在 App.xaml 中)?

c# - 如何将 xaml 转换为代码隐藏?

c# - System.Windows.Controls.Control 和 System.Windows.Forms.Control 有什么区别?

c# - 多边形自动调整到其上面的多边形

c# - 处理 WPF 用户控件的事件

asp.net-mvc - 将带有字符串的 json 数组发布到 Asp.Net MVC Action Controller 始终为空