2015-09-10 54 views
0

我试图分组的ComboBox使用GroupStyle分组组合框显示组头,但没有项目

<ComboBox ItemsSource="{Binding GroupedItems}"> 
    <ComboBox.GroupStyle> 
     <GroupStyle> 
      <GroupStyle.HeaderTemplate> 
       <DataTemplate> 
        <TextBlock Text="{Binding Name}" /> 
       </DataTemplate> 
      </GroupStyle.HeaderTemplate> 
     </GroupStyle> 
    </ComboBox.GroupStyle> 
</ComboBox> 

这里的“GroupedItems”属性是ListCollectionView应用了“GroupDescription”。

这几乎奏效:标题正确,但项目本身不会出现在弹出窗口中。为什么?

注:我正在使用ComboBox styles/templates on MSDN的修改版本。

回答

0

事实证明,MSDN上的ComboBox控制模板是错误的,而且文档也是错误的。在我从我的资源中删除样式/模板后,我意识到这一点,然后分组显示正确。

萃取后,实际内置使用混合控制模板,我发现ComboBox的分组功能依赖于这些命名的部分:“弹出”(“PART_Popup”作为被列入MSDN),“下拉菜单“,”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> 

谢谢奥巴马!微软!