2010-05-05 31 views
0

我必須將數據分組到數據網格中。 我已經做以下爲:在datagrid中分組 - 行不顯示

  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> 
  • 我已經應用了風格:
  • <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> 
    
  • 我有infoList作爲的ObservableCollection和的ItemsSource如下分配了它:

    的ListCollectionView LCV =新的ListCollectionView(infoList); lcv.GroupDescriptions.Add(new PropertyGroupDescription(「Author」)); dgAuthor.ItemsSource = lcv;

  • 其中Info是具有Author,Book,Year屬性的類。

    我必須在Author屬性上對datagrid進行分組。 我能夠顯示說明,但看​​不到任何行。 有人可以告訴我最新的代碼有什麼問題嗎?

    回答

    0

    設置AutoGenerateColumns="True"明確地解決了這個問題。 我還添加了列定義。