2012-12-17 5 views
2

Datagrid 그룹화 예제 here at MSDN으로 작업하고 있습니다. 예제의 코드는 Expander를 사용하여 그룹의 하위 행을 표시합니다. 내 코드에서 Expander를 사용하고 싶지 않습니다. 모든 행을 항상 표시하고 싶습니다. 확장기 컨트롤을 사용하지 않고 그룹화 된 DataGrid에 하위 행을 표시하려면 어떻게합니까?확장기없이 데이터 그리드를 그룹화하는 방법

답변

4

확장기를 사용하는 대신 테두리를 사용할 수 있습니다.

<DataGrid.GroupStyle> 
       <!-- Style for groups at top level. --> 
       <GroupStyle> 
        <GroupStyle.ContainerStyle> 
         <Style TargetType="{x:Type GroupItem}"> 
          <Setter Property="Margin" Value="0,0,0,0"/>        
          <Setter Property="Template"> 
           <Setter.Value> 
            <ControlTemplate TargetType="{x:Type GroupItem}"> 
             <Border BorderThickness="1" BorderBrush="Black" CornerRadius="5,5,5,5" Margin="0,0,0,5"> 
              <StackPanel> 
               <StackPanel Height="30" Orientation="Horizontal"> 
                <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="100" VerticalAlignment="Center"/> 
                <TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}" VerticalAlignment="Center" /> 
               </StackPanel> 

               <ItemsPresenter /> 
              </StackPanel> 
             </Border> 
            </ControlTemplate> 
           </Setter.Value> 
          </Setter> 
         </Style> 
        </GroupStyle.ContainerStyle> 
       </GroupStyle> 
       <!-- Style for groups under the top level. --> 
       <GroupStyle> 
        <GroupStyle.HeaderTemplate> 
         <DataTemplate> 
          <DockPanel Background="LightBlue"> 
           <TextBlock Text="{Binding Path=Name, Converter={StaticResource completeConverter}}" Foreground="Blue" Margin="30,0,0,0" Width="100"/> 
           <TextBlock Text="{Binding Path=ItemCount}" Foreground="Blue"/> 
          </DockPanel> 
         </DataTemplate> 
        </GroupStyle.HeaderTemplate> 
       </GroupStyle> 
</DataGrid.GroupStyle> 
+0

그래도 작동합니다. 감사! – user1214135

관련 문제