我有一个DataGridTextColumn包含一个布尔值,这些布尔值在列上返回TRUE或FALSE。布尔转换器打印图像,只是打印图像名称c#
我想用两个图像替换它,一个为TRUE,一个为FALSE。
这是在DataGrid:
<DataGrid x:Name="DonneesBrutes" IsReadOnly="True" ItemsSource="{Binding Path=ResultatCollectionGrande}" Margin="10,65,0,0" AutoGenerateColumns="False" EnableRowVirtualization="True" RowDetailsVisibilityMode="VisibleWhenSelected">
<DataGrid.Columns>
<DataGridTextColumn x:Name="PrisEnCompte" Width="50" Binding="{Binding Path=Flag, Converter={StaticResource BooleanConverter}}" Header="PEC"></DataGridTextColumn>
与资源:
<Window.Resources>
<local:BooleanConverter x:Key="BooleanConverter"/>
</Window.Resources>
这是转换器:
public class BooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value.Equals(true)) return @"booleanTrue.png";
return @"booleanFalse.png";
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
转换的作品,它改变了什么我DataGridTextColumn显示器。现在它显示“booleanTrue.png”为TRUE和“booleanFalse.png”,但它不显示图像。
我该如何display'em,我错过了什么以在我的DataGrid中打印这些图像?
在此先感谢您的帮助。
转换器不一定要返回Uris。它也可以是字符串,因为WPF的内置类型转换可以类型化ImageSource(Image控件的'Source'属性的类型)适用于两者。此外,当图像作为程序集资源(我将从OP中假设)存储时,您将不得不返回有效的[资源文件包URI](http://msdn.microsoft.com/zh-cn/library/aa970069。 ASPX#Resource_File_Pack_URIs ___ Local_Assembly)。另一种方法是直接创建并返回BitmapImage或BitmapFrame实例。 – Clemens 2014-10-01 09:32:52