How to programmatically switch to a new pivot item in Windows Phone 7
Posted by robkraft on April 3, 2011
I hope the title of my article does not mislead you, but I just learned today that you cannot programmatically change which pivot item is displayed in the pivot control from your C# code. Apparently this is a known bug:
Unfortunately for me this is a fairly devasting problem because my whole user interface (UI) is based on the Pivot Control and I needed my search function in the application to send me to a specific PivotItem. But code like this does not work:
PivotControl.SelectedIndex = 3;
I spent an hour or two before I started writing my application trying to decide if a Pivot Control or non Pivot based UI would work best. Had I known that the pivotcontrol was not working as expected, I certainly would have not used it. Fortunately I have also been writing unit tests and using MVVM on this project which is going to make putting an entirely different UI on the application relatively simple. I estimate 2 to 8 hours. Of course since I only work on this on the evenings and weekends the calendar time is going to cost me a week.
I am using the latest Microsoft Phone Developer SDK (release in February 2011). Hopefully the next SDK will fix this bug.