WPF ListBox的分组面板
我有一个列表框,它使用 GroupStyle 对项目进行分组。我想在堆栈面板的底部添加一个控件来保存所有组。此附加控件需要成为滚动内容的一部分,以便用户滚动到列表底部才能看到该控件。如果我使用没有组的列表框,则通过修改列表框模板可以轻松完成此任务。但是,对于已分组的项目,ListBox 模板似乎仅适用于每个组。我可以修改 GroupStyle.Panel,但这不允许我向该面板添加项目。
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/> **<----- I would like to add a control to this stackpanel**
</ItemsPanelTemplate>
</GroupStyle.Panel>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Grid>
<ItemsPresenter />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListBox.GroupStyle>
这应该让我知道我需要做什么:
I have a listbox that is grouping the items with a GroupStyle. I would like add a control at the bottom of the stackpanel that holds all of the groups. This additional control needs to be part of the scrolling content so that the user would scroll to the bottom of the list to see the control. If I were using a listbox without the groups, this task would be easy by modifying the ListBox template. However, with the items grouped, the ListBox template seems to only apply on a per group basis. I can modify the GroupStyle.Panel, but that doesn't allow me to add items to that panel.
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/> **<----- I would like to add a control to this stackpanel**
</ItemsPanelTemplate>
</GroupStyle.Panel>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Grid>
<ItemsPresenter />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListBox.GroupStyle>
This should give an idea of what I need to do:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用为
ListBox
计划的策略,只需为GroupItem
执行该策略即可。如果您将此 XAML 添加到您的GroupStyle
中,它将添加一个组结束TextBlock
:编辑:
这是一个完整的仅 XAML带有滚动条和添加到滚动区域末尾的附加内容的分组列表示例:
You can use the strategy you were planning on for a
ListBox
, just do it for aGroupItem
instead. If you add this XAML to yourGroupStyle
, it will add an end-of-groupTextBlock
:Edit:
Here is a complete XAML-only example of a grouped list with a scrollbar and additional content added to the end of the scrolling region: