分组CollectionView的组可以水平呈现吗?
我正在按照这个答案实现一个ListBox,其ItemsPanel是一个WrapPanel,但有一个转折:我的ItemsSource是一个分组的CollectionView。将
GroupStyle
应用于我的ListBox后,该问题中显示的包装不起作用:组始终垂直显示。
窥探我的应用程序,原因如下:
如您所见,定义为ListBox的ItemsPanelTemplate的WrapPanel出现在每个GroupItem中的ItemsPresenter中;创建一个隐式的,垂直方向的StackPanel(粉红色框中的顶部项)来包含GroupItems本身。
有没有办法覆盖这种行为,所以GroupItems放在一个WrapPanel?我是否需要重新模板化整个ListBox?
更新:为了说明我对ListBox和CollectionView分组的实际操作,让我发布一个小XAML:
<Grid>
<ListBox ItemsSource="{Binding}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionMode="Multiple"
ItemContainerStyle="{StaticResource itemStyle}">
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" FontWeight="Bold"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListBox.GroupStyle>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type WpfApplication1:Item}">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Name}" FontSize="10"/>
<TextBlock Text="{Binding Amount, StringFormat={}{0:C}}" FontSize="10"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
GroupStyle
是它的核心:如果你删除它,GroupItems就不会被渲染,并且WrapPanel(你可以在上面的截图中看到出现在GroupItem下面)代替屏幕截图中的(StackPanel)98 。
没有找到相关结果
已邀请:
2 个回复
荤碗
它看起来像这样:
澜悍景哭苟
或者,您还应该能够基于组项对象创建DataTemplate: