Accessing images from isolated storage in XAML using “isostore:/” scheme

北城以北 提交于 2019-12-05 17:56:14

I think I've done exactly the same thing that you're trying to do. What I've found is the absolute location where the Isolated Storage stores the file using IsolatedStorageFile.GetUserStoreForApplication(). This is something like "C:/Data/Users/DefApps/AppData/<App Product ID>/Local/<YourFile.png>";

I've tested this workaround on Windows Phone 8 and it works for me...

1. XAML

<Image Width="40">
    <Image.Source>
        <BitmapImage DecodePixelWidth="40" DecodePixelHeight="40" UriSource="{Binding Path=Icon}" />
    </Image.Source>
</Image>

2. ViewModel

private string _icon;
public string Icon
{
    get
    {
        return _icon;
    }
    set
    {
        if (value != _icon)
        {
            _icon = value;
            NotifyPropertyChanged("Icon");
        }
    }
}

3. Load data

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 });

Sadly it seems this is not possible after all. I am a bit shocked and a lot disappointed by this. Can't really understand how MS doesn't support this case.

This is the answer I got over at MSDN forums:

It Will Not Support XAML Binding Directly From Isolated Storage With ISOStore URI Scheme.

Here is Detailed Answer For Your Answer.

http://mark.mymonster.nl/2013/05/24/yeah-windows-phone-supports-isolated-storage-access-through-an-uri-scheme-does-it

So that's it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!