DataGrid.AlternatingRowBackground Property
Gets or sets the Brush that is used to paint the background of odd-numbered rows.
Namespace: System.Windows.Controls
Assembly: System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)
<sdk:DataGrid> <sdk:DataGrid.AlternatingRowBackground> singleBrush </sdk:DataGrid.AlternatingRowBackground> </sdk:DataGrid>
<sdk:DataGrid AlternatingRowBackground="colorString"/>
XAML Values
Property Value
Type: System.Windows.Media.BrushThe brush that is used to paint the background of odd-numbered rows. The default is a SolidColorBrush with a Color value of white (ARGB value #00FFFFFF).
Dependency property identifier field: AlternatingRowBackgroundProperty
The RowBackground property is used to paint the background for all rows in the control. However, if the AlternatingRowBackground property value is not null, 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 AlternatingRowBackground 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" AutoGenerateColumns="False" RowBackground="Azure" AlternatingRowBackground="LightSteelBlue">
The following code example demonstrates how to set the AlternatingRowBackground property in code. This example is part of a larger example available in the Walkthrough: Customizing the DataGrid Control Using Properties topic.
private void cbAltRowBrush_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBoxItem cbi = ((ComboBox)sender).SelectedItem as ComboBoxItem; if (this.dataGrid1 != null) { if (cbi.Content.ToString() == "Custom") this.dataGrid1.AlternatingRowBackground = new SolidColorBrush(Color.FromArgb(255, 130, 175, 200)); else if (cbi.Content.ToString() == "Default") this.dataGrid1.AlternatingRowBackground = new SolidColorBrush(Color.FromArgb(37, 233, 238, 244)); else if (cbi.Content.ToString() == "Null") this.dataGrid1.AlternatingRowBackground = null; } }
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.