Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

silverlight - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...