的DataGrid:如何設置默認圖片?
<sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Tag="{Binding photo}" MinWidth="50" Source="{Binding photo, Converter={StaticResource ConvertNullImageKey}}"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
轉換器,如果沒有價值迴歸的URI從iamge ImageResource.noimage。但是,這個位圖...如何返回位圖上的URI?
public class ConvertNullImage : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
Uri uri = new Uri(value.ToString(), UriKind.Relative);
return uri;
}
catch { return new Uri(ImageResource.noimage); }
}
public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
throw new NotImplementedException();
}
}