0

I am trying to save a list of backstack pages that are Tombstoned, so that when I navigate back to them, I can compare if they are present in this list. If yes, I'll restore its state.

Currently my code looks like this.

public partial class App : Application
{
    public static List<PhoneApplicationPage> TombstonedPages = new List<PhoneApplicationPage>();
    private void Application_Activated(object sender, ActivatedEventArgs e)
    {
        if(!e.IsApplicationInstancePreserved)
        {
            foreach (JournalEntry j in (Application.Current.RootVisual as PhoneApplicationFrame).BackStack)
            {                    
                TombstonedPages.Add(//What should i add here);                 

            }
        }
    }
}

code in some PhoneApplicationPage

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        //checking tombstone
        if(e.NavigationMode== NavigationMode.Back &&  App.TombstonedPages.Contains(this)  )
        {
            //restore state and delete entry from App.TombstonedPages

        }
    }
 protected override void OnNavigatedFrom(NavigationEventArgs e)
    {
        if(e.NavigationMode != NavigationMode.Back)
        {
           //save state
        }
    }

But I am unable to get a reference of pages from backstack. How should I do this? Is there a different way to do this?

Rishabh876
  • 3,010
  • 2
  • 20
  • 37
  • //What should i add here:- Try adding this ((App.Current.RootVisual as PhoneApplicationFrame).Content as PhoneApplicationPage) – Vyas Dec 24 '14 at 06:03
  • @Vyas_27 wouldn't that only the current page's content and not the whole backstack that I want to add – Rishabh876 Dec 24 '14 at 06:07
  • You will be saving the entire page not it's content(PhoneApplicationFrame's Current Content i.e. CurrentPage) & is it not the page you want to check? – Vyas Dec 24 '14 at 06:10
  • @Vyas_27 ohk yes, I forgot to save the current page in this code. But still, all the pages that are in backstack will also lose their state when tombstoned. how will I restore them. I will be needing their refrence too in that TombstonedPages list – Rishabh876 Dec 24 '14 at 06:15
  • 1
    try adding the same code TombstonedPages.Add(((App.Current.RootVisual as PhoneApplicationFrame).Content as PhoneApplicationPage)); in you ONNAVIGATEDFROM Event's in your Pages... This way you will have refrence to the backstack itself, it's like maintaining your own backstack. See if this helps. – Vyas Dec 24 '14 at 06:21
  • @Vyas_27 I'll keep that option as my last resort as it will need modification in all pages. Still thanks – Rishabh876 Dec 24 '14 at 06:30
  • @Vyas_27 So I tried making my own copy of backstack in App class. But that is also flushed on Tombstoned. If I try to save it in PhoneApplicationService.Current.State then I get an error that PhoneApplicationPage can't be serialized. – Rishabh876 Dec 24 '14 at 08:01

0 Answers0