2011-05-10 6 views
1

데이터 그리드를 두 수준으로 그룹화합니다. 각 주 그룹에는 하나 이상의 하위 그룹이 있습니다. 나는 하위 그룹을 차별화하려는Wpf DataGrid 하위 그룹 스타일

<controls:DataGrid.GroupStyle> 
      <GroupStyle> 
       <GroupStyle.HeaderTemplate> 
        <DataTemplate> 
         <StackPanel> 
          <TextBlock Text="{Binding Path=Name}" /> 
         </StackPanel> 
        </DataTemplate> 
       </GroupStyle.HeaderTemplate> 
       <GroupStyle.ContainerStyle> 
        <Style TargetType="{x:Type GroupItem}"> 
         <Setter Property="Template"> 
          <Setter.Value> 
           <ControlTemplate TargetType="{x:Type GroupItem}"> 
            <Expander IsExpanded="True" Style="{DynamicResource newExpanderStyle}" HorizontalAlignment="Left" 
              Margin="5,0,0,0" VerticalAlignment="Top" Background="{DynamicResource NormalBrushGrid}" > 
             <Expander.Header> 
              <StackPanel Background="#E5E5E5" Orientation="Horizontal"> 
               <TextBlock Text="{Binding Path=Name}" FontWeight="Bold" FontSize="12" Margin="5,0" /> 
               <TextBlock Text="{Binding Path=ItemCount}"/> 
              </StackPanel> 
             </Expander.Header> 
             <ItemsPresenter /> 
            </Expander> 
           </ControlTemplate> 
          </Setter.Value> 
         </Setter> 
        </Style> 
       </GroupStyle.ContainerStyle> 
      </GroupStyle> 
     </controls:DataGrid.GroupStyle> 

주요 group.How에서 나는 사전

찬드에 하위 그룹 헤더에

덕분에 다른 색상을 적용 할 수 있습니다.

답변

2

그룹은 많은 정보를 제공하지 않지만 하나의 하위 레벨 만있는 경우 CollectionViewGroup.IsBottomLevel을 사용하여 구분할 수 있습니다. 예 :

<GroupStyle.HeaderTemplate> 
    <DataTemplate> 
     <TextBlock Text="{Binding Name}"> 
      <TextBlock.Style> 
       <Style TargetType="{x:Type TextBlock}"> 
        <Style.Triggers> 
         <DataTrigger Value="True"> 
          <DataTrigger.Binding> 
           <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Content.IsBottomLevel"/> 
          </DataTrigger.Binding> 
          <Setter Property="Foreground" Value="Red"/> 
         </DataTrigger> 
        </Style.Triggers> 
       </Style> 
      </TextBlock.Style> 
     </TextBlock> 
    </DataTemplate> 
</GroupStyle.HeaderTemplate> 

형판 부모는 ContentPresenter이며 그 Content의 내부 그룹 클래스이다.

+0

Msdn는 XAML에서이 속성을 설정할 수 없다고 말합니다. – Hukam

+0

설정하려고하지 않았습니까? –

+0

시도해주세요. – Hukam