Reputation: 834
I was migrating my app from WP7 to WP8, and a funny thing is happening. I've a databound pivot who works perfectly in WP7. But, in WP8, the exact same code, doesn't load the first PivotItem. I've tried all the solutions in the question for WP7, none works (I want a solution, not an ugly workaround). I'm setting the DataContext in the constructor, the collection is OK, and everything should work. It only loads pivots when I scroll in the app. Anyone has any solution?
Upvotes: 3
Views: 4302
Reputation: 7437
I created a repro of this bug here: https://github.com/michaellperry/PivotIsBroken
It appears that the bug occurs because the content animation is not triggered. The selected index is not actually changing.
The ugly workaround that I employed is similar to DavidN's recommendation, but I had to insert a dummy page. Setting SelectedIndex to 1 with only one page throws an exception.
Upvotes: 0
Reputation: 111
If it helps i had the same problem, did an ugly fix but it worked..
pivotTest.SelectedIndex = 1;
pivotTest.SelectedIndex = 0;
Upvotes: 0
Reputation: 16102
I can't repro any databinding issues with Pivot on WP8. There is a known issue with Panorama Databinding on WP8, but not Pivot. What exactly doesn't work for you?
Here's a basic WP8 Pivot Databinding code that works just fine for me.
C# code setting a DataContext to 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 that DataContext as the ItemSource and Binding PivotItem.Header and PivotItem.Content to 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>
Works just fine...
Upvotes: 5