Backstack Tombstone wp7

2019-09-08 05:16发布

I have just finished tombstoning a page in my application when I noticed that I only tombstone the page I am currently viewing, meaning that after I return the pages in the backstack lose all their members and doesn't get tombstoned.. I only find examples on how to tomstone the current page but nothing about tombstoning the backstack pages... What is the elegant way to do this?

Just to show How I'm tombstoning:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    if (e.IsNavigationInitiator == false)
    {
        _tombstone = this.LoadState<Tombstone>("tombstone");
    }
    else
    {
        _tombstone.NavigationParameters = NavigationParameters;
    }
}


protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    if (_tombstone != null && e.IsNavigationInitiator == false)
        this.SaveState("tombstone", _tombstone);
}

    public static void SaveState(this PhoneApplicationPage phoneApplicationPage, string key, object value)
    {
        if (phoneApplicationPage.State.ContainsKey(key))
        {
            phoneApplicationPage.State.Remove(key);
        }

        phoneApplicationPage.State.Add(key, value);
    }

_tombstone contains all the vital members of my current page which I need to reinitialize the page after tombstoneing

1条回答
甜甜的少女心
2楼-- · 2019-09-08 05:55

You should persist the data for each page as you leave it (if NavigationMode != Back) as you won't know it the app will be tombstoned when on another page and you wont' be able to access the other pages in the stack when tombstoning occurs.

Alternatively, you can store everything centrally (with a super view model) and handle state persistence at an application level.

查看更多
登录 后发表回答