简体   繁体   中英

data from the same source is displayed in the pivot header but not in the pivot item template

I am binding data to a pivot element in UWP. The data is displayed in the header template but the same header data when i try to display in the item template inside, it is not being shown. Why is this happening?? Also, the same data is being displayed in the item template outside the grid view.

  <Pivot x:Name="Pivot1" ItemsSource="{Binding Store_Product_x}" SelectionChanged="Pivot1_SelectionChanged">
                <Pivot.HeaderTemplate>
                    <DataTemplate >
                        <TextBlock Text="{Binding Course_Header}"/>
                    </DataTemplate>
                </Pivot.HeaderTemplate>
                <Pivot.ItemTemplate>
                    <DataTemplate>
                        <!--<TextBlock Text="{Binding Course_Header}"/>-->
                        <GridView ItemsSource="{Binding Store_Product_x}">
                            <GridView.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Course_Header}"/>
                                </DataTemplate>
                            </GridView.ItemTemplate>
                        </GridView>
                    </DataTemplate>
                </Pivot.ItemTemplate>
            </Pivot>

For Pivot , one PivotHeader corresponds one PivotItem . And in your code one PivotItem also corresponds one GridView . If the above code can run and meet your requirements, the GridView will only have one item under every PivotItem and value is same with PivotHeader , in that case why did we need the GridView ?

For example, the itemsource Store_Product_x have two records and you bind to the Pivot . So the Pivot will have two items with headers shown. The first item is bind record 1 of Store_Product_x , and the second item is bind record 2 of Store_Product_x . At the same time, under every item you have a GridView . The first GridView has same source with first item which is record 1, how it bind Store_Product_x which contains record 1?

Please clear that the PivotItem to GridViewItems in your code is 1 to many relationship. Your above code is obviously wrong. Please reference the nested bind I mentioned in your previous thread.

If you cannot think out a right structure to meet your requirements you can consider change the control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM