【发布时间】:2019-02-07 22:43:28
【问题描述】:
编辑 #2:
这是我为重现问题而创建的最小Github Repo。
我认为这是在某些组为空时实现分组 ListViewBase 虚拟化的一个错误
我有一个列表视图,其项目面板设置为 StackPanel,因为我需要将组样式面板设置为交错面板,这与项目堆栈面板不兼容。
现在的问题是,在 27 个组中,只显示了 16 个组。我在另一个列表视图中对其进行了测试,并确认问题在于堆栈面板仅显示有限数量的子项(奇怪的是我的测试不是 16 个,而是 22 个)。
我尝试了 VirtualizingStackPanel,但与 StackPanel 不同的是,在设置 MaxWidth 时,我似乎无法将它置于列表视图的中心,尽管它显示了它的所有子项。
这是我的 XAML:
<ListView ItemsSource="{Binding Source={StaticResource NoteViewSource}}"
Padding="0 0"
ItemTemplate="{StaticResource NormalNoteTemplate}"
x:Name="ListView"
IsItemClickEnabled="True"
ItemClick="ListView_OnItemClick"
SelectionChanged="ListView_OnSelectionChanged"
SelectionMode="Extended">
<ListView.Footer>
<Border Height="80" />
</ListView.Footer>
<ListView.GroupStyle>
<GroupStyle HidesIfEmpty="False">
<GroupStyle.HeaderTemplate>
<DataTemplate x:DataType="viewModels:NoteList">
<TextBlock Text="{x:Bind Header, Mode=OneWay}"
FontSize="18"
Margin="0,16,0,8"
FontWeight="Bold" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<uwp:SGStaggeredPanel DesiredColumnWidth="220"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</ListView.GroupStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<!-- custom group panel won't work if this is item panel-->
<StackPanel />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
编辑:
我进一步检查了它,似乎 StackPanel 不是问题,因为它的子项计数为 22。这意味着它的子项计数错误,这意味着问题出在 CollectionViewSource 或 ListView 中仅传递了 22 个项目StackPanel 而不是完整的计数。
但我不明白的是,VirtualizingStackPanel 为什么会起作用?
【问题讨论】:
-
VirtualizingStackPanel 启用 UI 虚拟化,但 StackPanel 没有 UI 虚拟化。
标签: c# xaml uwp windows-community-toolkit