代码之家  ›  专栏  ›  技术社区  ›  Archie

在DataGrid中分组-未显示行

  •  0
  • Archie  · 技术社区  · 15 年前

    我必须对数据报中的数据进行分组。 为此,我做了以下工作:

    1. 已将样式添加到资源:
    > <Style x:Key="GroupHeaderStyle"
    > TargetType="{x:Type GroupItem}">
    >         <Setter Property="Template">
    >             <Setter.Value>
    >                 <ControlTemplate TargetType="{x:Type GroupItem}">
    >                     <Expander IsExpanded="False"
    >                      >
    >                         <Expander.Header>
    >                             <TextBlock Text="{Binding Name}"/>
    >                 </Expander.Header>
    >                         <ItemsPresenter />
    >                     </Expander>
    >                 </ControlTemplate>
    >             </Setter.Value>
    >         </Setter>
    >     </Style>
    
    1. 我将样式应用为:
        <dg:DataGrid Grid.Row="1" Name="dgAuthor" HorizontalScrollBarVisibility="Hidden"
    AutoGenerateColumns="False" RowHeaderWidth="17" RowHeight="25">
                    <dg:DataGrid.GroupStyle>
                        <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
                            <GroupStyle.Panel>
                                <ItemsPanelTemplate>
                                    <dg:DataGridRowsPresenter/>
                                </ItemsPanelTemplate>
                            </GroupStyle.Panel>
                        </GroupStyle>
                    </dg:DataGrid.GroupStyle>
               </dg:DataGrid>
    
    1. 我将信息列表作为一个可观察的集合,并将其指定为项源,如下所示:

      listcollectionview lcv=新建listcollectionview(infolist); 添加(new propertygroupdescription(“author”)); dgauthor.itemssource=lcv;

    其中info是具有author、book、year属性的类。

    我必须将DataGrid分组到author属性。 我可以显示解释程序,但看不到其中的任何行。 有人能告诉我密码有什么问题吗?

    1 回复  |  直到 15 年前
        1
  •  0
  •   Archie    15 年前

    设置 AutoGenerateColumns="True" 明确地解决了这个问题。 我还添加了列定义。