Backstack Tombstone wp7

眉间皱痕 提交于 2020-01-06 19:57:29

问题


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:


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.



来源:https://stackoverflow.com/questions/10799901/backstack-tombstone-wp7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!