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