Reputation: 102753
I'm attempting a grouped ComboBox
using GroupStyle
:
<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.
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.
Upvotes: 2
Views: 538
Reputation: 102753
It turns out that the ComboBox
control template on MSDN is wrong, and the documentation is also wrong. 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".
<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!
Upvotes: 2