Monday, April 11, 2011

WP7: Pivot bug

In a WP7 application we are building we have a databound pivot control:

<controls:Pivot x:Name="Pivoter" Title="{Binding Title}"
TitleTemplate="{StaticResource PivotTitleTemplate}"
HeaderTemplate="{StaticResource PivotHeaderTemplate}"
ItemsSource="{Binding Items}"      
ItemTemplate="{StaticResource DisplayItemDataTemplate}">
</controls:Pivot >

The Items property we are binding to is an observablecollection. When the page is displayed it creates all of the pivot items but the first item does not get created unless I scroll forward and back to it. It has an entry in the scroll list but no PivotItem control.

I couldn’t find a good reason what causes this, but I have a workaround. By setting the pivot-controls SelectedIndex to 1 in the page-loaded-event, it magically started working.

Its not an ideal solution, but it works.

No comments: