In this part of the tutorial, an image is retrieved from a File Picker and added to the application's Most Recently Used List so it can be saved and retrieve when the app is suspended or terminated. The problem I am running into is the image is not getting restored when I re-launch the app.
I tracked the problem down to the navigationHelper_LoadState method.
In the navigationHelper_LoadState method, e.PageState is always coming in as Null. Thus the page cannot restore the Image saved to the MostRecentlyUsedList.
Using the debugger, I can see that e.PageState is getting the mruToken key and value saved to it's dictionary when I navigate away from the page, but when I navigate back to the page, e.PageState is Null.
private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
if (e.PageState != null && e.PageState.ContainsKey("mruToken"))
{
object value = null;
if (e.PageState.TryGetValue("mruToken", out value))
{
if (value != null)
{
mruToken = value.ToString();
// open the file
Windows.Storage.StorageFile file =
await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(mruToken);
if (file != null)
{
Windows.Storage.Streams.IRandomAccessStream fileStream =
await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
new Windows.UI.Xaml.Media.Imaging.BitmapImage();
bitmapImage.SetSource(fileStream);
displayImage.Source = bitmapImage;
this.DataContext = file;
}
}
}
}
}
No comments:
Post a Comment