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

有帮助吗?

解决方案

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);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top