I don't know why people are suggesting you do it in one page. The image will still be blank if the screen goes idle or the user presses the start button to check a text or phone call. Saving the page state should be part of your normal page code. In your case, just save the image as a bmp to isolated storage in OnNavigatedFrom(..), and restore it in OnNavigatedTo(..).
e.g when the page is navigated away...
if (bmp != null)
{
string tmpfilename = "TempJPEG" + Guid.NewGuid().ToString();
WriteableBitmap bitmap = new WriteableBitmap(bmp);
IsolatedStorageFileStream myFileStream = IsolatedStorageFile.GetUserStoreForApplication().CreateFile(tmpfilename);
bitmap.SaveJpeg(myFileStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
myFileStream.Close();
State["ImageTempFileName"] = tmpfilename;
bmp = null;
}
when you navigate back, check if there's a saved state...
if (State.ContainsKey("ImageTempFileName")) //isNewInstance N/A here since we set the bmp to null on navigatefrom
{
string tmpfilename = (string)State["ImageTempFileName"];
bmp = new BitmapImage();
try
{
using (IsolatedStorageFileStream isoStreamRead = new IsolatedStorageFileStream(tmpfilename, System.IO.FileMode.Open, IsolatedStorageFile.GetUserStoreForApplication()))
{
bmp.SetSource(isoStreamRead);
myImage.Source = bmp;
myImage.Stretch = Stretch.Uniform;
}
}
catch (IsolatedStorageException ex)
{
System.Diagnostics.Debug.WriteLine("IsolatedStorageException: " + ex.Message);
}
IsolatedStorageFile.GetUserStoreForApplication().DeleteFile(tmpfilename);
}
Not too difficult.