DataGrid.AlternatingRowBackground 属性

定义

获取或设置在可选行上使用的背景画笔。

public System.Windows.Media.Brush AlternatingRowBackground { get; set; }

属性值

用于绘制每 n 行的背景的 Brush,其中 n 由 AlternationCount 属性定义。 已注册的默认值为 null。 有关可以影响值的因素的更多信息,请参见 DependencyProperty

示例

以下示例演示如何在 上 DataGrid设置交替行背景色。

<DataGrid x:Name="CustomerGrid" ItemsSource="{Binding}" AlternatingRowBackground="LightBlue" AlternationCount="2" />

下图显示了此代码在运行时的外观。

行背景的三种交替颜色

注解

AlternatingRowBackgroundRowBackgroundAlternationCount 属性共同决定每一行背景的外观。

如果 AlternationCount 小于 2,请将 AlternatingRowBackground 属性设置为 AlternationCount 2。

适用于

产品 版本
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅