我已经从网上下载了图像并将它们保存到独立存储中,现在我想在我的 XAML 文件中访问这些图像,并提供一个 Uri 作为对它们的引用。
我已经使用 IsoStoreSpy 验证它们是否正确存储在我期望的位置,并且如果我打开文件并读取字节流,我可以从中创建 BitmapImages。但现在我想通过仅将模型中的 Uri 传递到isolatedStorage 位置并让我的 XAML 加载图像来优化图像处理。
<Image Height="120" Width="120" Stretch="Uniform" HorizontalAlignment="Left">
<Image.Source>
<BitmapImage UriSource="{Binding PodcastLogoUri}" DecodePixelHeight="120" DecodePixelWidth="120" />
</Image.Source>
</Image>
这是PodcastLogoUri
绑定到 BitmapImage.UriSource 的 Uri 值:
“isostore:/PodcastIcons/258393889fa6a0a0db7034c30a8d1c3322df55696137611554288265.jpg”
这是我的构建方式:
public Uri PodcastLogoUri
{
get
{
Uri uri = new Uri(@"isostore:/" + PodcastLogoLocation);
return uri;
}
}
不过,我在用户界面中看不到图像。我确信该图像位于PodcastLogoLocation
.
是否可以像 Windows Phone 8 中那样将图像从独立存储引用到 UI?我究竟做错了什么?
Edit:如果我直接使用相同的路径创建 BitmapImage 并在 XAML 中使用 BitmapImage,它工作正常,我可以看到我期望在那里看到的图像:
<Image Height="120" Source="{Binding PodcastLogo}" Width="120" Stretch="Uniform" HorizontalAlignment="Left"/>
public BitmapImage PodcastLogo
{
get
{
Stream stream = null;
BitmapImage logo = new BitmapImage();
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isoStore.FileExists(PodcastLogoLocation))
{
stream = isoStore.OpenFile(PodcastLogoLocation, System.IO.FileMode.Open, FileAccess.Read);
try
{
logo.SetSource(stream);
}
catch (Exception e)
{
}
}
}
return logo;
}
}