Alex Rivera | Logout

How to programmatically set selected Panorama item in WP7

Asked 2011-01-07T03:15:56.780
13

I'm using a panorama control in a WP7 app. One of the PanoramaItems takes you to another page, which then allows you send an email through the EmailComposeTask. If you don't select to send the email and press the back button, the Panorama returns to the item you last selected. However, if you do select to send an email (and therefore leave the app), it does not return to the previously selected PanoramaItem. Instead, it returns to the first item in the Panorama. I tried keeping track of the selected index and setting it, but I got an error saying the SelectedIndex is not settable. This is confirmed on MSDN documentation http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.panorama.selectedindex%28VS.92%29.aspx

Is there any way to manually set the selected index/item on a panorama? If not, is there a way for it to remember what was selected, even if the user leaves the app to compose an email?

Edit
Report

1 Answer

1

I'm using this model to change to a pivot when the device goes into landscape view, I'll probably end up extracting the current item to the application state. The panorama is a no-go in landscape orientation.

private int hub_page_index;

protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
    base.OnOrientationChanged(e);

    if (panorama.Visibility == Visibility.Visible)
    {
        hub_page_index = panorama.SelectedIndex;
    }
    else if (pivot.Visibility == Visibility.Visible)
    {
        hub_page_index = pivot.SelectedIndex;
    }

    if (e.Orientation == PageOrientation.Landscape
     || e.Orientation == PageOrientation.LandscapeLeft
     || e.Orientation == PageOrientation.LandscapeRight)
    {
    // Display Pivot in Landscape orientation
        pivot.SetValue(Pivot.SelectedItemProperty, pivot.Items[panorama.SelectedIndex]);
        panorama.Visibility = Visibility.Collapsed;
        pivot.Visibility = Visibility.Visible;
    }
    else
    {
        // Display Panorama in Portrait orientation
        panorama.SetValue(Panorama.SelectedItemProperty, panorama.Items[pivot.SelectedIndex]);
        pivot.Visibility = Visibility.Collapsed;
        panorama.Visibility = Visibility.Visible;
    }
}
answered 2013-03-31T19:40:36.247

Your Answer