Backstack墓碑wp7 [英] Backstack Tombstone wp7

查看:123
本文介绍了Backstack墓碑wp7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我注意到我仅对当前正在查看的页面进行逻辑删除时,我刚刚完成了对应用程序中页面的逻辑删除,这意味着在我将这些页面退回到堆栈中后,将失去所有成员并且不会被逻辑删除.只能找到有关如何对当前页面进行逻辑删除的示例,而对于如何对后退页面进行逻辑删除则无济于事...这样做的优雅方法是什么?

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?

仅显示我的墓碑状态:

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包含了当前页面的所有重要成员,在进行逻辑删除后,我需要重新初始化页面

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

推荐答案

您应该在保留每个页面的数据时将其保留(如果NavigationMode!= Back),因为您不知道在打开时该应用程序将被删除另一个页面,并且在发生逻辑删除时您将无法访问堆栈中的其他页面.

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.

这篇关于Backstack墓碑wp7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆