Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DataGrid.ColumnHeaderStyle Property

Gets or sets the style that is used when rendering the column headers.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)
public Style ColumnHeaderStyle { get; set; }
<sdk:DataGrid>
  <sdk:DataGrid.ColumnHeaderStyle>
    inlineStyle
  </sdk:DataGrid.ColumnHeaderStyle>
</sdk:DataGrid>
<sdk:DataGrid ColumnHeaderStyle="styleReference"/>

XAML Values

inlineStyle

A single Style object element.

styleReference

A StaticResource reference to a Style.

Property Value

Type: System.Windows.Style
The style applied to column headers. The default is null.

Dependency property identifier field: ColumnHeaderStyleProperty

The DataGridColumnHeader type is located in the System.Windows.Controls.Primitives namespace, in the System.Windows.Controls.Data assembly. Because of this, to set the TargetType property for a Style, you will have to add a XAML namespace mapping in your code.

Whether defined as an inline style or as a resource, the Style defines the appearance of the column header in the data grid, and should specify TargetType of DataGridColumnHeader. You typically would specify setters for individual properties, and might also use a setter for the Template property if you wanted to change the composition of elements. For information that can help you decide whether to define styles inline or as resources, see Inline Styles and Templates.

The following example shows how to set the ColumnHeaderStyle property.


<sdk:DataGrid x:Name="DG" ItemsSource="{Binding}" HeadersVisibility="All" >


...


<sdk:DataGrid.ColumnHeaderStyle>
    <Style  TargetType="sdk:DataGridColumnHeader" >
        <Setter Property="FontSize" Value="10" />
        <Setter Property="ContentTemplate" >
            <Setter.Value>
                <DataTemplate >
                    <StackPanel>
                    <TextBlock Text="Property:" />
                    <TextBlock Text="{Binding}" />
                </StackPanel>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</sdk:DataGrid.ColumnHeaderStyle>


...



</sdk:DataGrid>


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.