我正在尝试创建一个ListView
分组,其中每个组中的元素水平显示(作为可滚动内容)。无论我尝试什么GroupStyle.Panel
of the ListView
它似乎对列表没有任何影响。
我的 XAML 如下所示:
<ListView x:Name="itemListView"
Padding="10"
SelectionMode="None"
IsSwipeEnabled="False"
IsItemClickEnabled="True"
ItemTemplate="{StaticResource listItemTemplate}">
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<ItemsWrapGrid ItemWidth="144" Orientation="Horizontal" />
</ItemsPanelTemplate>
</GroupStyle.Panel>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding DisplayTitle}"
Margin="0,10,0,5"
Foreground="Black"
Style="{StaticResource SubheaderTextBlockStyle}"
TextWrapping="NoWrap" />
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
Where
<Page.Resources>
<DataTemplate x:Key="listItemTemplate">
<Grid Width="144" Margin="5">
<!-- details -->
</Grid>
</DataTemplate>
</Page.Resources>
下图左侧显示了我得到的实际结果,右侧显示了我想要的结果。
我尝试使用ItemsWrapGrid
具有不同的属性,我尝试了StackPanel
甚至一个VariableSizedWrapGrid
,但列表项的显示方式没有任何变化。
如何才能做到这一点?
@kubakista 是对的
看起来如果 ListView.ItemsPanel 包含 ItemsStackPanel 那么
GroupStyle.Panel 被忽略...
然而,改变这个并不能解决你的问题,因为 -
- 滚动变得有点滞后。
- 没有水平滚动。
- The
ListView
失去虚拟化。
- 漂亮的组标题滚动动画消失了。
这是一种不改变结构的替代方案ListView
本身只是对数据结构进行一点修改。
这个想法是,将一组下的每个水平矩形列表视为一件收藏品在用户界面上。
这意味着,组中的每个组ListView
只会有一个子项,它实际上是一组矩形,将以水平可滚动的形式呈现ItemsControl
.
所以,假设你有一些类型的集合ObservableCollection<Item>
as the CollectionViewSource
, the Item
现在将成为类型<ObservableCollection<Item>>
为了保存矩形的集合。因此,集合的类型需要更新为类似ObservableCollection<ObservableCollection<Item>>
.
在 - 的里面ListView
's ItemTemplate
,您需要创建一个水平滚动的ScrollViewer
并放一个ItemsControl
里面。确保您已经设置了后者ItemsSource
to {Binding}
.
要启用水平滑动,您需要禁用tilt通过编辑默认样式的效果ListViewItem
并注释掉以下代码。
<!--
<VisualStateGroup.Transitions>
<VisualTransition From="Pressed" To="Normal">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="TiltContainer"/>
</Storyboard>
</VisualTransition>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="Pressed">
<Storyboard>
<PointerDownThemeAnimation Storyboard.TargetName="TiltContainer"/>
</Storyboard>
</VisualState>
-->
我附上了一个工作示例项目here以及下面显示的屏幕截图。
希望这可以帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)