Unhandled Exception When Setting Pivot Control SelectedItem/SelectedIndex Property to 3rd Pivot Item (WP7) - by vitriolicobloquy

Status : 

  Not Reproducible<br /><br />
		The product team could not reproduce this item with the description and steps provided.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


18
0
Sign in
to vote
ID 604360 Comments
Status Closed Workarounds
Type Bug Repros 18
Opened 9/23/2010 9:59:53 PM
Access Restriction Public

Description

Setting SelectedItem Property to the 3rd Item of a pivot control inside OnNavigatedTo Handler results in Unhandled Exception. Consider the following Example:

C#:
NavigationService.Navigate(new Uri("/PivotPage.xaml?PivotItem2",UriKind.Relative));

PivotPage.xaml Excerpt:
<controls:Pivot x:Name="PivotControlName" Title="Pivot Control Title">
 <controls:PivotItem x:Name="PivotItem0" Header="Zero"><Grid/></controls:PivotItem>
 <controls:PivotItem x:Name="PivotItem1" Header="One"><Grid/></controls:PivotItem>
 <controls:PivotItem x:Name="PivotItem2" Header="Two"><Grid/></controls:PivotItem>
 <controls:PivotItem x:Name="PivotItem3" Header="Three"><Grid/></controls:PivotItem>
</controls:Pivot>

PivotPage.xaml.cs Excerpt:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
 if (NavigationContext.QueryString.ContainsKey("PivotItem0"))
  PivotControlName.SelectedItem = PivotItem0; //Works
 else if (NavigationContext.QueryString.ContainsKey("PivotItem1"))
  PivotControlName.SelectedItem = PivotItem1; //Works
 else if (NavigationContext.QueryString.ContainsKey("PivotItem2"))
  PivotControlName.SelectedItem = PivotItem2; //Unhandled Exception
 else if (NavigationContext.QueryString.ContainsKey("PivotItem3"))
  PivotControlName.SelectedItem = PivotItem3; //Works
}

Pretty rudimentary, easily reproduced. A more succinct example would be:

public partial class PivotPage : PhoneApplicationPage
{
   public PivotPage()
   {
      InitializeComponent();
      PivotControlName.SelectedItem = PivotControlName.Items[2]; //Unhandled Exception
      /* PivotControlName.SelectedIndex = 2; //Unhandled Exception
       */
   }
}

(See Also: http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/092fe7ba-f3e6-4e3d-8651-d7f201a9c454/)
Sign in to post a comment.
Posted by Zipp425 on 4/7/2012 at 8:28 PM
The weird part about this bug is that for a while I didn't have it... Now I do.
While the workarounds work... They leave an ugly transition from the first pivot to the selected pivot. Anyone have a better one?
Posted by vysakhbalakrishnan on 9/13/2011 at 2:32 AM
thanks a lot for the post. i was also getting the same problem with selectedindex 2 & 3.
i tried this
Loaded += delegate { PivotControlName.SelectedIndex = 2; }; // Works
as posted by mr.vitriolicobloquy
now it is solved.. once again thanks a lot
Posted by devaddi aka MSicc on 7/30/2011 at 11:58 AM
This Problem exists still, also in a WP7 Pivot App
Posted by Bobby J Cannon on 11/13/2010 at 2:18 PM
I'm seeing the same thing with indexes of 2 or 3.
Posted by GoldenCrater-322540 on 10/13/2010 at 12:35 PM
@sri2 : Thanks! This worked for me too.

Funny, it was working on one page, I copied and pasted it the xaml/cs, removed one PivotItem, and it the copy started crashing.
Posted by Microsoft on 9/28/2010 at 6:11 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by Microsoft on 9/28/2010 at 6:11 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by vitriolicobloquy on 9/23/2010 at 11:31 PM
Loaded += delegate { PivotControlName.SelectedIndex = 2; }; // Works