简体   繁体   中英

Need to Tombstone Panorama Control in Windows Phone 8

I am using Panorama control to display items in Windows Phone 8 now I want to save the state of selected PanoramaItem and display the same item as default on navigating back to this page. Like we save it in Tombstone. But in Windows Phone 8 Panorama selectedItem and SelectedIndex are on readonly property as shown in below code description: How can i achieve this in Windows Phone 8 Panorama Control. 在此处输入图片说明

You can use SetValue on the Panorama control:

private const string SELECTED_PANORAMA_INDEX_KEY = "selectedPanoramaIndex";

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    // restore selected panorama item
    if (State.ContainsKey(SELECTED_PANORAMA_INDEX_KEY))
    {
        int ndx = (int)State[SELECTED_PANORAMA_INDEX_KEY];
        if(MainPanorama.SelectedIndex != ndx)
            MainPanorama.SetValue(Panorama.SelectedItemProperty, MainPanorama.Items[ndx]);
    }
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    State[SELECTED_PANORAMA_INDEX_KEY] = MainPanorama.SelectedIndex;

    base.OnNavigatedFrom(e);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM