How converter null to ImageNull.jpg
This code not work? column don't show
<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>
Converter:
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();
}
}
What you are currently doing is taking an existing BitmapImage
and trying to assign another BitmapImage
to its UriSource
. Have you tried this:-
<Image Tag="{Binding photo}" MaxHeight="50" Source="{Binding photo, Converter={StaticResource ConvertNullImageKey}}" />
精彩评论