I've downloaded images from the web and saved them to the Isolated Storage and now I want to access those images in my XAML file, giving a Uri as a reference to them.
I have verified with IsoStoreSpy that they are stored properly where I would expect them to be and I can create BitmapImages from them if I open the file and read in the byte stream. But now I want to optimize my image handling by passing just a Uri from my model to the IsolatedStorage location and letting my 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 that is bound to BitmapImage.UriSource:
"isostore:/PodcastIcons/258393889fa6a0a0db7034c30a8d1c3322df55696137611554288265.jpg"
Here's how I've constructed it:
public Uri PodcastLogoUri
{
get
{
Uri uri = new Uri(@"isostore:/" + PodcastLogoLocation);
return uri;
}
}
Still, I can't see an image in my UI. And I am sure the image is at PodcastLogoLocation
.
Should it be possible to reference images to the UI from the isolated storage like this in Windows Phone 8? What am I doing wrong?
Edit: If I create the BitmapImage directly using the same path and use the BitmapImage in XAML, it works fine and I can see the image 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;
}
}
UriKind.Absolute
? – Neil Turner