DataGridColumn.HeaderStyle DataGridColumn.HeaderStyle DataGridColumn.HeaderStyle DataGridColumn.HeaderStyle Property


取得或設定呈現欄標題時所用的樣式。Gets or sets the style that is used when rendering the column header.

 property System::Windows::Style ^ HeaderStyle { System::Windows::Style ^ get(); void set(System::Windows::Style ^ value); };
public System.Windows.Style HeaderStyle { get; set; }
member this.HeaderStyle : System.Windows.Style with get, set
Public Property HeaderStyle As Style


用來呈現資料行標題的樣式,或 null 表示使用 ColumnHeaderStyle 設定。The style that is used to render the column header; or null, to use the ColumnHeaderStyle setting. 已註冊的預設值是 nullThe registered default is null. 如需哪些因素會影響值的詳細資訊,請參閱 DependencyPropertyFor information about what can influence the value, see DependencyProperty.


下列範例會使用樣式資源來變更中DataGrid的資料行標頭樣式。The following example uses a style resource to change the style of column headers in the DataGrid. 第一個資料行標頭的樣式接著會使用覆寫的DataGrid.ColumnHeaderStyle內嵌樣式來設定。The style of the first column header is then set with an inline style that overrides the DataGrid.ColumnHeaderStyle.

    <!-- DataGrid style -->
    <Style x:Key="DataGridStyle1" TargetType="{x:Type DataGrid}">
        <Setter Property="ColumnHeaderStyle" Value="{DynamicResource ColumnHeaderStyle1}"/>
    <!-- DataGridColumnHeader style -->
    <Style x:Key="ColumnHeaderStyle1" TargetType="DataGridColumnHeader">
        <Setter Property="Height" Value="30"/>
        <Setter Property="Background" Value="LightBlue"/>
        <Setter Property="Foreground" Value="Blue"/>
        <Setter Property="FontSize" Value="18" />
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="ToolTip" Value="Click to sort."/>
    <DataGrid Name="dataGrid1" Margin="12,12,0,0" 
              Style="{DynamicResource DataGridStyle1}">
            <DataGridTextColumn Header="Name" 
                                Binding="{Binding Name}">
                <!-- Local Style for header of first DataGrid column. -->
                    <Style TargetType="DataGridColumnHeader">
                        <Setter Property="Background" Value="Blue"/>
                        <Setter Property="Foreground" Value="White"/>
                        <Setter Property="FontSize" Value="24"/>
            <DataGridTextColumn Header="Class"
                                Binding="{Binding Classification}" />
            <DataGridCheckBoxColumn Header="Extinct"
                                    Binding="{Binding Extinct}"/>


若要定義Style資料行標題的,請TargetType指定的DataGridColumnHeaderTo define a Style for a column header, specify a TargetType of DataGridColumnHeader.

Style可以套用至所有資料行標頭,或套用至個別的資料行標題。A Style can be applied to all column headers or to an individual column header. 若要將Style套用至個別的標頭, DataGridColumn.HeaderStyle請設定屬性, DataGrid.ColumnHeaderStyle其優先于屬性。To apply a Style to an individual header, set the DataGridColumn.HeaderStyle property, which takes precedence over the DataGrid.ColumnHeaderStyle property.