This documentation is archived and is not being maintained.

DataGrid.RowHeaderStyle Property

Gets or sets the style applied to all row headers.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

public Style RowHeaderStyle { get; set; }
    <Style .../>

Property Value

Type: System.Windows.Style
The style applied to all row headers in the DataGrid. The registered default is null. For more information about what can influence the value, see DependencyProperty.

Apply a Style to update the visual appearance of all the row headers in the DataGrid. To define a Style for a row header, specify a TargetType of DataGridRowHeader.

You can also use the RowHeaderStyle property to update any property of DataGridRowHeader.

A Style can be applied to all row headers, or to an individual row header. To apply a Style to an individual header, set the DataGridRow.HeaderStyle property, which takes precedence over the DataGrid.RowHeaderStyle property.

The following example shows how to display numbered rows in the row header by applying a binding with a value converter to the Content property of the DataGridRowHeader. The converter is created as a resource by mapping the namespace and creating an instance of the class. For more information, see Data Binding Overview.

    <local:ConvertItemToIndex x:Key="IndexConverter"/>     
    <DataGrid Name="DG1" ItemsSource="{Binding}" CanUserAddRows="False" CanUserDeleteRows="False" >
        <!--Bind the Content property of the RowHeaderStyle to the Converter to create numbered rows-->
            <Style TargetType="{x:Type DataGridRowHeader}">
                <Setter Property="Content" Value="{Binding Converter={StaticResource IndexConverter}}" />

public class ConvertItemToIndex : IValueConverter
    #region IValueConverter Members
    //Convert the Item to an Index
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            //Get the DataRowView that is being passed to the Converter
            System.Data.DataRowView drv = (System.Data.DataRowView)value;
            //Get the CollectionView from the DataGrid that is using the converter
            DataGrid dg = (DataGrid)Application.Current.MainWindow.FindName("DG1");
            CollectionView cv = (CollectionView)dg.Items;
            //Get the index of the DataRowView from the CollectionView
            int rowindex = cv.IndexOf(drv)+1;

            return rowindex.ToString();
        catch (Exception e)
            throw new NotImplementedException(e.Message);
     //One way binding, so ConvertBack is not implemented
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        throw new NotImplementedException();


.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.