DataBound Pivot 控件未创建第一个 PivotItem [英] DataBound Pivot control is not creating the first PivotItem
问题描述
在 Windows Phone 7 页面中,我有以下控件:
</controls:Pivot >
使用此数据模板:
<Image Grid.Column="0" Stretch="Uniform"Source="{Binding LargeImage, Converter={StaticResource UriBitmapConverter}}"/><StackPanel Grid.Column="1" Orientation="垂直"><HyperlinkButton NavigateUri="{Binding Uri}" Content="{Binding Uri}"/></StackPanel></数据模板>
ItemsSource
是一个 ObservableCollection
.显示页面时,它会创建所有 PivotItems
,但除非我向前和向后滚动,否则不会创建第一个项目.它在滚动列表中有一个条目,但没有 PivotItem
控件.
如果我在 Pivot Control 的 LoadingPivotItem
事件中设置断点,则在第一次显示枢轴时不会调用它,但只有在我滚动并返回到第一个项目时才会再次被击中.>
有没有人看到 Pivot
控件的类似行为并有解决方法?还是我做错了什么?
我遇到了同样的问题.
看来应该在构造函数中设置枢轴的 DataContext.我在 Page_Loaded 事件中设置了我的 DataContext 并且第一个数据透视项不会触发 Loading 事件,如上所述.通过之前简单地绑定我的 DataContext,事件开始触发.
我认为这是框架中的一个错误,但我还没有做足够的工作来确认.
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?
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.
这篇关于DataBound Pivot 控件未创建第一个 PivotItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!