我想将ObservableCollection数据绑定到WP7中的透视控制点,以便ObservableCollection中的每个对象都变为透视对象。这是我使用的代码:在WP7上将数据透视项目数据绑定到ObservableCollection
<controls:Pivot x:Name="MainPivot" ItemsSource="{Binding Persons}">
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding FullName}"/>
</DataTemplate>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<TextBlock Text="{Binding FirstName}"/>
<TextBlock Text="{Binding LastName}"/>
<TextBlock Text="{Binding HomeTown}"/>
</StackPanel>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
这工作,并与我的ObservableCollection TRE项目我得到三个PivotItems。但是当所有东西都被加载后,DataTemplate中的绑定就不会被更新。只有当我滚动到下一个PivotItem时,FirstName,LastName和HomeTown才会被加载。
这是为什么?我错过了什么?
谢谢
嗨乔纳斯。这是我无法看到的“第一个”pivotitem的属性。当我滑到显示出来的“下一个”,当我滑回去时,“第一”也如此。 – 2011-02-03 09:55:47
你什么时候创建ObservableCollection,你什么时候添加项目?我测试我创建并在构造函数之前添加项目之前设置DataContext – 2011-02-03 10:24:42