[英]Grouped ComboBox shows group headers, but not items
I'm attempting a grouped ComboBox
using GroupStyle
: 我正在尝试使用
GroupStyle
分组的ComboBox
:
<ComboBox ItemsSource="{Binding GroupedItems}">
<ComboBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ComboBox.GroupStyle>
</ComboBox>
Here the "GroupedItems" property is a ListCollectionView
with a "GroupDescription" applied. 在这里,“ GroupedItems”属性是一个应用了“ GroupDescription”的
ListCollectionView
。
This almost works: the headers are correct, but the items themselves do not appear in the popup. 这几乎可行:标题正确,但项目本身未出现在弹出窗口中。 Why?
为什么?
Note: I'm using the a modified version of the ComboBox
styles/templates on MSDN . 注意:我正在MSDN上使用
ComboBox
样式/模板的修改版。
It turns out that the ComboBox
control template on MSDN is wrong, and the documentation is also wrong. 事实证明,MSDN上的
ComboBox
控件模板是错误的,并且文档也是错误的。 I realized this after I removed the styles/templates from my resources, and then the grouping showed up correctly. 从资源中删除样式/模板后,我意识到了这一点,然后正确显示了分组。
After extracting the actual built-in control template using Blend, I found that the grouping functionality of the ComboBox
relies on these named parts: "Popup" ( not "PART_Popup" as is listed on MSDN), "DropDown", "DropDownBorder", "DropDownScrollViewer", and "ItemsPresenter". 使用Blend提取实际的内置控件模板后,我发现
ComboBox
的分组功能依赖于以下命名部分:“ Popup”( 不是 MSDN上列出的“ PART_Popup”),“ DropDown”,“ DropDownBorder”, “ DropDownScrollViewer”和“ ItemsPresenter”。
<Popup x:Name="Popup">
<Grid x:Name="DropDown">
<Border x:Name="DropDownBorder">
<ScrollViewer x:Name="DropDownScrollViewer">
<ItemsPresenter x:Name="ItemsPresenter" />
</ScrollViewer>
</Border>
</Grid>
</Popup>
Thanks Obama! 谢谢奥巴马
! Microsoft! 微软!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.