DataGrid.RowBackground Property

Gets or sets the Brush that is used to paint row backgrounds.

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


Public Property RowBackground As Brush
public Brush RowBackground { get; set; }
<sdk:DataGrid RowBackground="colorString"/>

XAML Values

  • singleBrush
    Within opening and closing property elements for sdk:DataGrid.RowBackground, exactly one object element for an object that derives from Brush. The object element is typically one of the following Silverlight classes: LinearGradientBrush, RadialGradientBrush, ImageBrush, SolidColorBrush, or VideoBrush.

  • colorString
    The Color for a SolidColorBrush expressed as an attribute string. This can be a named color, an RGB value, or an ScRGB value. RGB or ScRGB may also specify alpha information. See Color.

Property Value

Type: System.Windows.Media.Brush
The brush that is used to paint row backgrounds. The default is a SolidColorBrush with a Color value of semi-opaque light grey (ARGB value #55E9EEF4).


Dependency property identifier field: RowBackgroundProperty

The RowBackground property is used to paint the background for all rows in the control. However, if the AlternatingRowBackground property value is not nulla null reference (Nothing in Visual Basic), its value overrides the default background value for rows with odd-numbered index values (which are zero-based).


The following code example demonstrates how to set the RowBackground property. This example is part of a larger example available in the DataGrid class overview.

<sdk:DataGrid x:Name="dataGrid5" 
    Height="125" Margin="0,5,0,10"

The following code example demonstrates how to set the RowBackground property in code. This example is part of a larger example available in the Walkthrough: Customizing the DataGrid Control Using Properties topic.

Private Sub cbRowBrush_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim cb As ComboBox = sender
    Dim cbi As ComboBoxItem = cb.SelectedItem
    If Me.dataGrid1 IsNot Nothing Then
        If cbi.Content.ToString() = "Custom" Then
            Me.dataGrid1.RowBackground = New SolidColorBrush(Color.FromArgb(255, 135, 185, 195))
        ElseIf cbi.Content.ToString() = "Default" Then
            Me.dataGrid1.RowBackground = New SolidColorBrush(Color.FromArgb(0, 255, 255, 255))
        ElseIf cbi.Content.ToString() = "Null" Then
            Me.dataGrid1.RowBackground = Nothing
        End If
    End If
End Sub
private void cbRowBrush_SelectionChanged(object sender, SelectionChangedEventArgs e)
    ComboBoxItem cbi = ((ComboBox)sender).SelectedItem as ComboBoxItem;
    if (this.dataGrid1 != null)
        if (cbi.Content.ToString() == "Custom")
            this.dataGrid1.RowBackground = new SolidColorBrush(Color.FromArgb(255, 135, 185, 195));
        else if (cbi.Content.ToString() == "Default")
            this.dataGrid1.RowBackground = new SolidColorBrush(Color.FromArgb(00, 255, 255, 255));
        else if (cbi.Content.ToString() == "Null")
            this.dataGrid1.RowBackground = null;

Version Information


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.