绑定后,PivotItems不会调整大小 [英] PivotItems do not resize after binding

查看:70
本文介绍了绑定后,PivotItems不会调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绑定PivotItems,但根据我的保证金声明,以某种方式无法正确调整项目的大小.为什么呢?

I am binding a PivotItems but somehow the items are not resized properly, according to my margin declaration. Why is that?

这是我的新代码,仍然存在空白.

    <Pivot x:Name="TpsSegmentsPivot" Title="Locator" Foreground="#FF888888" Style="{StaticResource PivotStyle1}" SelectionChanged="Pivot_SelectionChanged" Margin="0" Grid.Row="1" ItemTemplate="{StaticResource TpTemplate}" ItemsSource="{Binding DataSource}">
        <Pivot.HeaderTemplate>
            <DataTemplate>
                <Grid>
                    <TextBlock Text="{Binding id}" Margin="0, 16, 0, 0" Foreground="#FF888888" FontSize="32" FontFamily="Segoe WP" FontWeight="Light"/>
                </Grid>
            </DataTemplate>
        </Pivot.HeaderTemplate>
    </Pivot>

这是模板:

<DataTemplate x:Key="TpTemplate">
    <ListBox Background="Black"
             ItemsSource="{Binding Seg}"
             ItemTemplate="{StaticResource SectionUCTemplate}"
             HorizontalAlignment="Stretch"
             VerticalAlignment="Top">
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
            </Style>
        </ListBox.ItemContainerStyle>
    </ListBox>
</DataTemplate>

这是带有红色pivotItem的屏幕截图.

Here is a screenshot with the red pivotItem..

推荐答案

我认为,额外空间的问题是您在DataTemplate标签内使用的Piviot物品.删除它,并将标头绑定到标头模板.我以前在Pivots上使用过数据绑定,但从未见过此问题.

I think the issue with the extra space is the Piviot Item you are using inside the DataTemplate tag. remove it and bind the header to a header template. I've used data binding on Pivots before and never seen this issue.

从我发布的一个应用程序中:

From one of my released apps:

<controls:Pivot Title="CAMPING CHECKLIST" ItemsSource="{Binding FilteredCategories}" Name="MainPivot">
    <controls:Pivot.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}" />
        </DataTemplate>
    </controls:Pivot.HeaderTemplate>
    <controls:Pivot.ItemTemplate>
        <DataTemplate>
            <!-- Your pivot item content here -->
        </DataTemplate>
    </controls:Pivot.ItemTemplate>
</controls:Pivot>

我相信PivotItem中的PivotItem是问题的根源.

I believe the PivotItem in a PivotItem is the root of your issue.

您的代码应类似于:

<controls:Pivot ItemsSource="{Binding tripTypeViewModel.TripTypeViewModelDataSource}" x:Name="TripsSegmentsPivot" Title=" " Foreground="#FF888888" Style="{StaticResource PivotStyle1}" SelectionChanged="Pivot_SelectionChanged" Grid.Row="1">
    <controls:Pivot.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding DataContext.tripTypeViewModel.HeaderText, ElementName=TripsSegmentsPivot}" Margin="0, 16, 0, 0" Foreground="#FF888888" FontSize="32" FontFamily="Segoe WP" FontWeight="Light"/>
        </DataTemplate>
    </controls:Pivot.HeaderTemplate>
    <controls:Pivot.ItemTemplate>
        <DataTemplate>
                <ListBox x:Name="ItemsLB" ItemsSource="{Binding DataContext.tripTypeViewModel.Segment, ElementName=TripsSegmentsPivot}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent">
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                        </Style>
                    </ListBox.ItemContainerStyle>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <local:SectionUC HorizontalAlignment="Stretch" Grid.Row="1" VerticalAlignment="Top"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
        </DataTemplate>
    </controls:Pivot.ItemTemplate>
</controls:Pivot>

第一张图片是我的描述方式,第二张图片是您当前的使用方式:

The first image is how I describe it, the second is how you currently have it :

这篇关于绑定后,PivotItems不会调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆