【发布时间】:2012-06-07 14:42:39
【问题描述】:
为 Metro Style 应用程序实现本地缓存以便在应用程序在线使用时在后台缓存图像并在应用程序离线时提供图像的最佳模式是什么?
在发现无法访问 Internet 时,如何将 BitmapSource 设置为本地文件?使用 new Uri(localpath, UriKind.Absolute) 不起作用。
【问题讨论】:
为 Metro Style 应用程序实现本地缓存以便在应用程序在线使用时在后台缓存图像并在应用程序离线时提供图像的最佳模式是什么?
在发现无法访问 Internet 时,如何将 BitmapSource 设置为本地文件?使用 new Uri(localpath, UriKind.Absolute) 不起作用。
【问题讨论】:
图片是否已经下载?如果是,它们是否在“本地”文件夹中?
如果是这样,您可以像这样从路径构建 BitmapImage
var m_Image = new BitmapImage(new Uri("ms-appdata:///local/" + ImageFileName));
编辑
如果您的文件以“从不访问且无法下载任何内容”的状态存储在包中,则 Uri 将类似于
var m_Image = new BitmapImage(new Uri("ms-appx:///Assets/" + FallBackImageFileName));
【讨论】: