在DataTemplate of a ListView中,我有以下代码
<Image Grid.Column = "1" Grid.ColumnSpan = "2" Grid.Row = "0" Source = "{Binding Picture}" VerticalAlignment = "center" />我是一个绑定图片属性的人。此属性是一个字符串,其地址指向web上的图像。在没有互联网连接的情况下,如何显示项目中的图像?
发布于 2015-05-28 21:47:49
一种快速的方法是订阅ImageFailed事件:
<Image Source="{Binding Picture}" ImageFailed="ImageFailed" />然后,在事件处理程序中,将Source属性更改为本地图片:
private void ImageFailed(object sender, ExceptionRoutedEventArgs e)
{
((Image)sender).Source = new BitmapImage(new Uri("ms-appx:///Assets/WideLogo.scale-240.png"));
}发布于 2015-05-28 21:48:18
这链接声明有一个Image.ImageFailed事件。可以在其处理程序中设置另一个源。
或者,您可以在视图模型代码中检查internet连接,并将图片值设置为类似于"ms-appx:///Assets/image_name.png"的内容。
发布于 2015-05-29 01:16:59
根据用例(比如在GridView中显示图像,您知道目标图像大小),另一个选项是始终显示默认图像,然后如果下载了正确的图像,它将显示在默认图像的顶部。
只需列出两张图片,第二张将显示在第一张图片的顶部。
<Grid>
<Image Source="{Binding DefaultPicture}" />
<Image Source="{Binding Picture}" />
</Grid>https://stackoverflow.com/questions/30517518
复制相似问题