小编Bjö*_*sen的帖子

在WP7上将PivotItems数据绑定到ObservableCollection

我想将一个ObservableCollection数据绑定到WP7中的Pivot contronl,以便我的ObservableCollection中的每个对象都变成一个PivotItem.这是我使用的代码:

    <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>
Run Code Online (Sandbox Code Playgroud)

这适用于我的ObservableCollection中的tre项目,我得到三个PivotItems.但是当一切都被加载时,DataTemplate内部的绑定将不会更新.只有当我滚动到下一个PivotItem时才会加载FirstName,LastName和HomeTown.

这是为什么?我错过了什么?

谢谢

pivot windows-phone-7

5
推荐指数
1
解决办法
5903
查看次数

标签 统计

pivot ×1

windows-phone-7 ×1