Domanda

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. enter image description here

È stato utile?

Soluzione

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);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top