Windows Phone 7:使用URI进行逻辑删除?

Nic*_*ner 5 silverlight windows-phone-7 tombstoning

我正在Silverlight中构建一个wp7应用程序.我的应用程序的所有状态都存储在NavigationContext.QueryString.如果这可以在应用程序停用时保存,并且该页面导航到应用程序重新激活时,那将照顾我对墓碑的要求.

但是,我不太清楚如何做到这一点.我正在考虑保存NavigationContext.QueryStringState字典中App.xaml.cs::Application_Deactivated(),但该代码无法访问NavigationContext.QueryString.还有其他方法可以做到这一点吗?

我想我每次导航时都可以将查询字符串保存到状态字典中,然后在重新激活应用程序时将其恢复.还是有更好的方法?

更新:根据indyfromoz的回答,我想实现以下内容

OnNavigatedToHandler()
{
     // save NavigationContext.QueryString in the State dictionary
}
Run Code Online (Sandbox Code Playgroud)

为了减少冗余,我想我会在继承的类中实现它PhoneApplicationPage,然后让我的所有其余页继承自该类.但是,我接着解决了所有页面类都存在的问题,partial因为它们也是在生成的代码中定义的.我不想更改生成的代码,因为每次重新生成代码时都会重新进行修改,这将是一个巨大的痛苦.

有一个更好的方法吗?

更新2:这是我现在在我的应用程序的主页面(在启动时导航到的那个)中一起攻击的内容:

public partial class MainPivot : PhoneApplicationPage
{
    public MainPivot()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(MainPivot_Loaded);
        PhoneApplicationService.Current.Deactivated += new EventHandler<DeactivatedEventArgs>(App_Deactivated);

        MessageBox.Show("launching main pivot (state count: " + PhoneApplicationService.Current.State.Count + ")");
        if (PhoneApplicationService.Current.State.Count != 0)
        {
            Debug.Assert(PhoneApplicationService.Current.State.ContainsKey(QueryStringKey), 
                "State is initialized, but contains no value for the query string");

            string oldQueryString = (string)PhoneApplicationService.Current.State[QueryStringKey];
            MessageBox.Show("Old query string: " + oldQueryString);
            NavigationService.Navigate(new Uri(oldQueryString));
        }
    }

    public readonly string QueryStringKey = "queryString";

    void App_Deactivated(object sender, DeactivatedEventArgs e)
    {
        PhoneApplicationService.Current.State[QueryStringKey] = NavigationService.Source;
    }

    // ...
Run Code Online (Sandbox Code Playgroud)

它有效(sorta),但它很难看.

更新3:看起来wp7操作系统将自动在基于页面的应用程序中重新加载正确的页面.我实际上是在使用页面,所以也许我在这里做的工作不多.

但是,它似乎没有起作用.我启动应用程序,转到页面,点击"开始",然后点击"返回".屏幕显示"正在恢复......"但似乎挂在那里.我的代码在这一点上应该以某种方式响应吗?有没有办法,即使在点击"开始"后我仍然可以保持调试器的连接?

ind*_*moz 5

瞬态数据通常存储在PhoneApplicationService类提供State字典中.数据存储在页面的OnNavigatedFrom事件中,并从页面的OnNavigatedTo事件中恢复.如果您在应用程序的每个页面中可用的OnNavigatedFrom事件中的状态字典中存储页面URI中的参数,则可以实现逻辑以读取OnNavigatedTo事件中的参数,从而处理逻辑删除

HTH,indyfromoz