Data binding reason does not load the first PivotItem in Windows Phone 8

I ported my application from WP7 to WP8 and it was funny. I have a support rod that works great in WP7. But, in WP8, the same code does not load the first PivotItem. I tried all the solutions in for WP7 , no one works (I want a solution, not an ugly workaround). I set the DataContext in the constructor, the collection is fine, and everything should work. It only loads anchor points when I view the application. Anyone have any solution?

+3
source share
3 answers

I can not reproduce any problems with data binding to Pivot on WP8. There is a known issue with Panorama Databinding on WP8 but not Pivot. What exactly does not work for you?

Here is the base WP8 Pivot Databinding binding code which works great for me.

C # code setting a DataContext for an observable collection of cows:

this.DataContext = new ObservableCollection<Cow>() { new Cow("Foo"), new Cow("Bar"), new Cow("Baz") }; public class Cow { public Cow(string name) { Name = name; } public string Name { get; set; } } 

XAML code using this DataContext as ItemSource and Binding PivotItem.Header and PivotItem.Content for the cow name.

 <phone:Pivot ItemsSource="{Binding}"> <phone:Pivot.HeaderTemplate> <DataTemplate> <ContentControl Content="{Binding Name}" /> </DataTemplate> </phone:Pivot.HeaderTemplate> <phone:Pivot.ItemTemplate> <DataTemplate> <ContentControl Content="{Binding Name}" /> </DataTemplate> </phone:Pivot.ItemTemplate> </phone:Pivot> 

It works well ...

Pivot with foo activePivot with bar active

+5
source

If this helps, I had the same problem, made an ugly fix, but it worked.

  pivotTest.SelectedIndex = 1; pivotTest.SelectedIndex = 0; 
0
source

I created a registry of this error here: https://github.com/michaellperry/PivotIsBroken

It seems that the error is due to the fact that the animation of the content does not start. The selected index does not actually change.

The ugly workaround I used was similar to DavidN's recommendation, but I had to insert a dummy page. Setting SelectedIndex to 1 with only one page throws an exception.

0
source

All Articles