2

As i'm using the Pivot control in my app, I wonder how can I resume to the last selected pivot item after the user tombstoned the app (Launched the App, pressed the windows button and pressend the back button to resume)?

(I tried to add some code in the Application_Deactivated and Application_Deactivated but didn't work)

4

3 回答 3

6

To save the state of the Pivot you should be using the State property of the page in the OnNavigatedTo and OnNavigatedFrom methods.

Here is a basic example:-

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        if (State.ContainsKey("pivotIndex"))
            myPivot.SelectedIndex = (int)State["pivotIndex"];
    }

    protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    {
        State["pivotIndex"] = myPivot.SelectedIndex;
    }

Note that the Windows Phone will handle the persisting of this state in the case where your application gets tombstoned. This approach also enables your page to navigate to elsewhere in the app and on navigation back your pivot state is restored.

于 2011-01-24T13:10:55.970 回答
2

If you keep track of your pivot's SelectedIndex, you can restore this value on return from tombstoning.

Here's a straight forward walkthrough on saving data when tombstoned.

Tombstoning on the Win7 Mobile Platform

于 2011-01-24T09:09:47.677 回答
1

To implement tombstoning you really need to add code to all of:

  • Save:

    • Application_Deactivated
    • Application_Closing
  • Load:

    • Application_Launching
    • Application_Activated

Then you also need to override "OnNavigatedTo" within the Pivot Page - this is the ideal time to set the SelectedIndex for your pivot.

于 2011-01-24T12:24:03.790 回答