Dan*_*n J 3 wpf grouping collectionview itemspaneltemplate
我正在按照这个答案实现一个ListBox,其ItemsPanel是一个WrapPanel ,但有一个转折:我的ItemsSource是一个分组的 CollectionView.随着GroupStyle应用到我的列表框,在这个问题出在包装不起作用:该组总是垂直显示.
窥探我的应用程序,原因如下:

正如你所看到的,WrapPanel,定义为我的列表框的ItemsPanelTemplate,出现在ItemsPresenter 内各GroupItem; 创建一个隐式的,垂直方向的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>
Run Code Online (Sandbox Code Playgroud)
它GroupStyle是它的核心:如果你删除它,GroupItems不会被渲染,并且WrapPanel(你可以在上面的截图中看到出现在GroupItem下面)出现在屏幕截图中的(StackPanel)98的位置.
如果您在GroupStyle中定义了HeaderTemplate,则似乎只会出现此行为.
可以通过将GroupStyle.Panel属性设置为包含WrapPanel来更正它:
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" FontWeight="Bold"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<WrapPanel></WrapPanel>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</ListBox.GroupStyle>
Run Code Online (Sandbox Code Playgroud)
它看起来像这样:

| 归档时间: |
|
| 查看次数: |
2777 次 |
| 最近记录: |