I have started using the Windows Phone 7 Panorama & Pivot Controls for a Windows Phone 7 application. In an OnNavigatedTo event, I'm trying to select which PivotItem to start the new View on. All SelectedItem
and SelectedIndex
seem to do is select the header. The content of the PivotItem is not shown and while the header is selected the phone has not animated to it. Here is my current implementation:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// URI is '/page/PivotItemToSelect'.
string selectedPivotItem = e.Uri.OriginalString.Split('/').Last();
// Match PivotItemToSelect with the PivotItem's Name.
PivotItem pivotItemToShow = MainPivotControl.Items.Cast<PivotItem>().Single(i => i.Name == selectedPivotItem);
MainPivotControl.SelectedItem = pivotItemToShow;
base.OnNavigatedTo(e);
}
I have also tried:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// URI is '/page/PivotItemIndex'.
string selectedPivotItemIndex = e.Uri.OriginalString.Split('/').Last();
int index = int.Parse(selectedPivotItemIndex);
MainPivotControl.SelectedIndex = index;
base.OnNavigatedTo(e);
}
Both of these implementations do what I described above. Am I missing a step in the selection process, trying to select a PivotItem too late in the lifecycle of the page, or does this version of the controls not yet support preselection?