C# 数据透视项在绑定后不调整大小
我正在绑定数据透视项目,但根据我的边距声明,这些项目的大小没有正确调整。为什么呢 编辑:这是我的新代码,它仍然有漏洞 这是模板: 这是一个带有红色数据透视项的屏幕截图C# 数据透视项在绑定后不调整大小,c#,xaml,mvvm,windows-phone,pivot,C#,Xaml,Mvvm,Windows Phone,Pivot,我正在绑定数据透视项目,但根据我的边距声明,这些项目的大小没有正确调整。为什么呢 编辑:这是我的新代码,它仍然有漏洞 这是模板: 这是一个带有红色数据透视项的屏幕截图 这是数据透视项的标准行为,因为它们总是以边距显示。您应该设置负边距: margin="-20,0,-20,0" 我认为额外空间的问题在于您在DataTemplate标记中使用的Piviot项。删除它并将标头绑定到标头模板。我以前在数据透视上使用过数据绑定,但从未见过这个问题 从我发布的一个应用程序: <controls:P
这是数据透视项的标准行为,因为它们总是以边距显示。您应该设置负边距:
margin="-20,0,-20,0"
我认为额外空间的问题在于您在DataTemplate标记中使用的Piviot项。删除它并将标头绑定到标头模板。我以前在数据透视上使用过数据绑定,但从未见过这个问题 从我发布的一个应用程序:
<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>
我相信数据透视项中的数据透视项是您问题的根源
您的代码应类似于:
<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>
第一个图像是我如何描述它的,第二个图像是您当前拥有它的方式:
在屏幕截图上,您可以看到红色轴项目没有边距8,8,8,0。。为什么会这样?请提供此页面的完整XAML。您所提供的代码之外的某些内容一定正在进行。具体来说,名为PivotStyle1的StaticResource中设置了多少边距?我不确定这是一个合适的解决方案。标准行为是什么意思?框架中的一个bug?我已经构建了一些带有pivots的应用程序,我一直都是这样做的。你可以在谷歌上搜索这个问题,你很难找到比设置负边际更好的解决方案。我不认为这是一个错误。只是支点总是有一个边距,明白了!无论如何,谢谢你:我会再次打开那篇帖子,因为有些东西让我很烦。数据透视项的标准行为意味着什么?如果我从代码后面以编程方式添加数据透视项,一切都很好,但当我使用数据绑定到viewModel时却不是这样。虽然这可能会使问题在视觉上消失,但实际上并没有解决根本原因。请参考我的答案。如果所有内容都正确嵌套,则边距不应成为问题。
<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>
<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>