Access images from isolated storage in XAML using the "isostore: /" scheme

I downloaded the images from the Internet and saved them in isolated storage, and now I want to access these images in my XAML file, providing Uri as a reference to them.

I checked with IsoStoreSpy that they are stored correctly, wherever I would expect them, and I can create BitmapImages from them if I open the file and read it in the byte stream. But now I want to optimize image processing by transferring only Uri from my model to IsolStorage and letting XAML load the image.

<Image Height="120" Width="120" Stretch="Uniform" HorizontalAlignment="Left"> <Image.Source> <BitmapImage UriSource="{Binding PodcastLogoUri}" DecodePixelHeight="120" DecodePixelWidth="120" /> </Image.Source> </Image> 

This is the PodcastLogoUri Uri value associated with BitmapImage.UriSource:

"isostore: /PodcastIcons/258393889fa6a0a0db7034c30a8d1c3322df55696137611554288265.jpg"

Here is how I built it:

 public Uri PodcastLogoUri { get { Uri uri = new Uri(@"isostore:/" + PodcastLogoLocation); return uri; } } 

However, I do not see the image in my interface. And I'm sure the image is on PodcastLogoLocation .

Is it possible to refer to images in the user interface from isolated storage, as it is in Windows Phone 8? What am I doing wrong?

Edit: If I create BitmapImage directly using the same path and use BitmapImage in XAML, it works fine and I see the image that I expect to see there:

 <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; } } 
+4
source share
2 answers

I think I did the same thing you are trying to do. What I found is the absolute place where isolated storage stores the file using IsolatedStorageFile.GetUserStoreForApplication() . This is something like "C:/Data/Users/DefApps/AppData/<App Product ID>/Local/<YourFile.png>" ;

I 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. Download 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 }); 
+5
source

Unfortunately, this seems to be impossible in the end. I am a little shocked and very disappointed with this. I can not understand how MS does not support this case.

This is the answer I got on the MSDN forums:

It will not support XAML binding directly from the ISIStore URI Scheme isolated storage.

Here is a 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 what is it.

+2
source

Source: https://habr.com/ru/post/1496300/


All Articles