4

为 Metro Style 应用程序实现本地缓存的最佳模式是什么,以便在应用程序在线使用时图像可以在后台缓存并在应用程序离线时提供图像?

在发现无法访问 Internet 时,我们如何将 BitmapSource 设置为本地文件?使用 new Uri(localpath, UriKind.Absolute) 不起作用。

4

1 回答 1

7

图像是否已经下载?如果是这样,它们是否在“本地”文件夹中?

如果是这样,您可以像这样从路径构建 BitmapImage

var m_Image = new BitmapImage(new Uri("ms-appdata:///local/" + ImageFileName));

编辑

如果您的文件存储在包中作为“永远无法访问且无法下载任何内容”备用,则 Uri 将类似于

var m_Image = new BitmapImage(new Uri("ms-appx:///Assets/" + FallBackImageFileName));
于 2012-06-07T15:27:51.837 回答