Expand Minimize

DataGrid.RowStyle Property

Gets or sets the style applied to all rows.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public Style RowStyle { get; set; }
<object>
  <object.RowStyle>
    <Style .../>
  </object.RowStyle>
</object>

Property Value

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

Apply a Style to change the visual appearance of all rows in the DataGrid. To define a Style for a row, specify a TargetType of DataGridRow.

A Style can be applied to all rows in the DataGrid or to an individual row. To apply a Style to an individual row, set the Style property directly on the DataGridRow, which takes precedence over the DataGrid.RowStyle property.

If this property has a non-null value, it will override the value of the ItemContainerStyle property.

The following example sets the Background color of all the rows and uses a trigger to change the Background and Foreground colors when the mouse pointer is over the row.


<DataGrid Name="dataGrid1" Margin="12,12,0,0">
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow">
            <Setter Property="Background" Value="LightBlue" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="Blue"/>
                    <Setter Property="Foreground" Value="White"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
</DataGrid>


The following illustration shows the output.

Custom DataGrid Row Style

.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.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft