【发布时间】:2011-03-16 14:35:17
【问题描述】:
我正在尝试将图像的网址 (BigImageURL) 与图像控件绑定。它大部分工作正常,但对于某些图像,我收到 http 403 错误(使用 fiddler 发现)并且显然图像没有显示。我想显示静态图像以防 http url 未解析。
<Image x:Name="HoverImage" Source="{Binding BigImageURL}" />
我试着写一个转换器
public class UriToImageSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType,object parameter, CultureInfo culture)
{
BitmapImage image = null;
try
{
image = new BitmapImage(new Uri(value.ToString()));
}
catch (Exception ex)
{
image= new BitmapImage(new Uri("..<mydefaultimageUrl>.."));
}
return image;
}
...
}
<Image x:Name="HoverImage" Source="{Binding BigImageURL,Converter={StaticResource myUriToImageSourceConverter}" />
没用!! 即使图像 url 不可访问,转换器也没有抛出任何异常。我认为它在创建 BitmapImage 时不会尝试解析地址或读取图像流
尝试设置 FallbackValue,但也没有用。
<Image x:Name="HoverImage" Source="{Binding BigImageURL,FallbackValue=DefaultUrl}"/>
任何指针??
提前致谢
【问题讨论】:
标签: data-binding silverlight-4.0