这段代码不起作用? 列不显示
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Tag="{Binding photo}" MaxHeight="50">
<Image.Source>
<BitmapImage UriSource="{Binding photo, Converter={StaticResource ConvertNullImageKey}}" />
</Image.Source>
</Image>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
转换器:
public class ConvertNullImage : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var image = new BitmapImage();
try
{
image = new BitmapImage(new Uri(value.ToString()));
return image;
}
catch { return new BitmapImage(new Uri("http://upload.wikimedia.org/wikipedia/commons/1/1c/No-Symbol.png")); }
}
public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
throw new NotImplementedException();
}
}
答案 0 :(得分:1)
您目前正在做的是采用现有BitmapImage
并尝试将另一个BitmapImage
分配给其UriSource
。你试过这个: -
<Image Tag="{Binding photo}" MaxHeight="50" Source="{Binding photo, Converter={StaticResource ConvertNullImageKey}}" />