2011-09-19 65 views

回答

1

希望這有助於...

<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> 
        <Expander.Header> 
         <StackPanel Orientation="Horizontal"> 
          <TextBlock Text="{Binding Path=Name}" /> 
          <TextBlock Text=" ("/> 
          <TextBlock Text="{Binding Path=ItemCount}"/> 
          <TextBlock Text=" "/> 
          <TextBlock Text="Items"/> 
          <TextBlock Text=")"/> 
         </StackPanel> 
        </Expander.Header> 
        <ItemsPresenter> 
         <ItemsPresenter.Resources> 
          <Style TargetType="{x:Type toolkit:DataGridRow}"> 
           <Style.Triggers> 
           <DataTrigger 
            Binding="{Binding RelativeSource= 
             {RelativeSource AncestorType={x:Type 
             GroupItem}}, Path=DataContext.Name}" 
            Value="1"> 
            <Setter Property="Background" 
              Value="LightGreen"/> 
           </DataTrigger> 
           <DataTrigger 
            Binding="{Binding RelativeSource= 
             {RelativeSource AncestorType={x:Type 
             GroupItem}}, Path=DataContext.Name}" 
            Value="2"> 
            <Setter Property="Background" 
              Value="LightPink"/> 
           </DataTrigger> 
           </Style.Triggers> 
          </Style> 
          </ItemsPresenter.Resources> 
         </ItemsPresenter> 
         </Expander> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </GroupStyle.ContainerStyle> 
</GroupStyle> 

數據觸發,高於該值,我們在創建的組檢查並相應地分配數據網格行的背景顏色。

因此,第一組代表文本「1」(LightGreen)下的所有值,下一組分組值代表值2(LightPink)。

相關問題