将true / false更改为图像
我在数据网格中有一个内容为True / false的列,如何根据文本将此true / false(boolean)更改为图像?
我正在使用c#wpf。
编辑:
使用DataGridTemplateColumn为包含Image的列提供DataTemplate,并使用值转换器或数据触发器根据列的值设置图像源。 以下是使用数据触发器的示例:
public class BoolToImage : IValueConverter { public Image TrueImage { get; set; } public Image FalseImage { get; set; } public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (!(value is bool)) { return null; } bool b = (bool)value; if (b) { return this.TrueImage; } else { return this.FalseImage; } } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }
然后在您的xaml中,作为资源:
然后在你的绑定:
ImageSource={Binding Path=BoolProp,Converter={StaticResource BoolImageConverter}}"
- 在unit testing中获取错误“Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl”但在主程序中没有
- “.NET框架默认使用UTF-16编码标准”是什么意思?
- 对象之间的区别a = new Dog()vs Dog a = new Dog()
- 如何使用.NET 4中的任务并行库链接异步操作?
- C#锁定在锁定块中重新分配的对象
- UOW – 在上一次异步操作完成之前,在此上下文中启动了第二个操作
- 如何从XML文档注释创建网站?
- 串行通信和CRLF C#
- 使用Entity Framework 5在SQL Server中连接字符串和数字的最佳方法?