Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataBound Pivot control is not creating the first PivotItem

In a Windows Phone 7 page I have the following control:

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

with this DataTemplate:

<DataTemplate x:Key="DisplayItemDataTemplate">    
    <Image Grid.Column="0" Stretch="Uniform"
        Source="{Binding LargeImage, Converter={StaticResource UriBitmapConverter}}"/>
    <StackPanel Grid.Column="1" Orientation="Vertical">
        <HyperlinkButton NavigateUri="{Binding Uri}" Content="{Binding Uri}"/>
    </StackPanel>    
</DataTemplate>

The ItemsSource is an ObservableCollection. When the page is displayed it creates all of the PivotItems 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.

If I put a break point in the Pivot Control's LoadingPivotItem event it is not called when the pivot is first displayed but again only gets hit when I scroll away and back to the first item.

Has anybody seen similar behavior for the Pivot control and have a work around? Or am I doing something incorrectly?

like image 362
dkackman Avatar asked Nov 06 '10 18:11

dkackman


1 Answers

I ran into this same problem.

It appears the DataContext for the pivot should be set in the constructor. I was setting my DataContext in the Page_Loaded event and the first pivot item would not fire the Loading event, as described. By simply binding my DataContext earlier, the event started firing.

I believe it's a bug in the framework, but I haven't done enough to confirm it.

like image 102
Jab Avatar answered Oct 05 '22 23:10

Jab