2017-04-11 114 views

回答

0

定義頁眉樣式:

<window.resources> 
    <style x:key="GroupHeaderStyle" targettype="{x:Type GroupItem}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
     <ControlTemplate TargetType="{x:Type GroupItem}"> 
      <Expander x:Name="exp" IsExpanded="True" 
      Background="White" 
      Foreground="Black"> 
      <Expander x:Name="exp" IsExpanded="True" 
         Background="Blue" 
         Foreground="Black"> 
         <Expander.Header> 
          <TextBlock Text="{Binding Name}" Foreground="Red"/> 
         </Expander.Header> 
         <ItemsPresenter /> 
        </Expander> 
      <ItemsPresenter /> 
      </Expander> 
     </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
    </style> 
</window.resources> 

並使用定義的樣式DataGrid中

<Custom:DataGrid x:Name="dgData" CanUserAddRows="False" AutoGenerateColumns="False" 
        CanUserDeleteRows="False" ItemsSource="{Binding}"> 
     <Custom:DataGrid.GroupStyle> 
      <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}"> 
       <GroupStyle.Panel> 
        <ItemsPanelTemplate> 
         <Custom:DataGridRowsPresenter/> 
        </ItemsPanelTemplate> 
       </GroupStyle.Panel> 
      </GroupStyle> 
     </Custom:DataGrid.GroupStyle> 
     <Custom:DataGrid.Columns> 
      <Custom:DataGridTextColumn Header="Name" Binding="{Binding Name}"/> 
      <Custom:DataGridTextColumn Header="Contact" Binding="{Binding Contact}"/> 
      <Custom:DataGridTextColumn Header="Email ID" Binding="{Binding EmailID}"/> 
      <Custom:DataGridTextColumn Header="Country" Binding="{Binding Country}"/> 
     </Custom:DataGrid.Columns> 
    </Custom:DataGrid> 

我已經使用背景= 「白」 前景= 「紅色」 爲分組酒吧,但你可以根據自己的選擇使用

相關問題