C# 使用“从XAML中的独立存储访问图像”;isostore:/“;方案

C# 使用“从XAML中的独立存储访问图像”;isostore:/“;方案,c#,xaml,windows-phone-8,isolatedstorage,C#,Xaml,Windows Phone 8,Isolatedstorage,我已经从web下载了图像并将它们保存到独立的存储中,现在我想访问我的XAML文件中的这些图像,并提供一个Uri作为它们的引用 我已经使用IsoStoreSpy验证了它们是否正确存储在我期望的位置,如果打开文件并读取字节流,我可以从它们创建位图图像。但是现在我想通过将Uri从模型传递到IsolatedStorage位置并让XAML加载图像来优化图像处理 <Image Height="120" Width="120" Stretch="Uniform" HorizontalAlignment=

我已经从web下载了图像并将它们保存到独立的存储中,现在我想访问我的XAML文件中的这些图像,并提供一个Uri作为它们的引用

我已经使用IsoStoreSpy验证了它们是否正确存储在我期望的位置,如果打开文件并读取字节流,我可以从它们创建位图图像。但是现在我想通过将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>
但是,我在UI中看不到图像。我确信图像位于
podcastlogocation

在Windows Phone 8中,是否可以像这样从独立存储中将图像引用到UI?我做错了什么

编辑:如果我直接使用相同的路径创建位图图像,并在XAML中使用位图图像,它工作正常,我可以看到我希望在那里看到的图像:

<Image Height="120" Source="{Binding PodcastLogo}"  Width="120" Stretch="Uniform" HorizontalAlignment="Left"/>

可悲的是,这似乎毕竟是不可能的。我对此感到有点震惊和失望。我真的不明白MS怎么不支持这个案子

这是我在MSDN论坛上得到的答案:

它将不支持直接从具有的独立存储进行XAML绑定 isostoreuri方案

下面是你的详细答案


就这样

我想我做了和你想做的完全一样的事情。我发现的是隔离存储使用
IsolatedStorageFile.GetUserStoreForApplication()
存储文件的绝对位置。这类似于
“C:/Data/Users/DefApps/AppData//Local/”

我已经在Windows Phone 8上测试了这个解决方法,它对我很有效

1。XAML

<Image Width="40">
    <Image.Source>
        <BitmapImage DecodePixelWidth="40" DecodePixelHeight="40" UriSource="{Binding Path=Icon}" />
    </Image.Source>
</Image>
3。加载数据

filename = "Myicon.png";

IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
if (!store.FileExists(filename))
{
    using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename, FileMode.Create, FileAccess.Write, store))
        stream.Write(imgBytes, 0, imgBytes.Length);
}

//get Product ID from manifest. Add using System.Linq; if you haven't already
Guid productId = new Guid((from manifest in System.Xml.Linq.XElement.Load("WMAppManifest.xml").Descendants("App") select manifest).SingleOrDefault().Attribute("ProductID").Value);
string storeFile = "C:/Data/Users/DefApps/AppData/" + productId.ToString("B") + "/Local/" + filename;

this.Items.Add(new MyViewModel() { Icon = storeFile });

是的,请尝试不使用UriKind.Absolute?谢谢您的建议,但没有任何帮助:-(也许我的问题并不像我预期的那样直截了当。我也在MSDN论坛上发布了它,但我没有得到任何答案。我真的认为这只是我没有摸索什么东西,我会很快让人指出这一点。不是这样的。
<Image Width="40">
    <Image.Source>
        <BitmapImage DecodePixelWidth="40" DecodePixelHeight="40" UriSource="{Binding Path=Icon}" />
    </Image.Source>
</Image>
private string _icon;
public string Icon
{
    get
    {
        return _icon;
    }
    set
    {
        if (value != _icon)
        {
            _icon = value;
            NotifyPropertyChanged("Icon");
        }
    }
}
filename = "Myicon.png";

IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
if (!store.FileExists(filename))
{
    using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename, FileMode.Create, FileAccess.Write, store))
        stream.Write(imgBytes, 0, imgBytes.Length);
}

//get Product ID from manifest. Add using System.Linq; if you haven't already
Guid productId = new Guid((from manifest in System.Xml.Linq.XElement.Load("WMAppManifest.xml").Descendants("App") select manifest).SingleOrDefault().Attribute("ProductID").Value);
string storeFile = "C:/Data/Users/DefApps/AppData/" + productId.ToString("B") + "/Local/" + filename;

this.Items.Add(new MyViewModel() { Icon = storeFile });