1、单行颜色的改变
按照以前WinForm的思想,应该是直接获得单行的对象,然后设置BackGround即可,但是在WPF 中DataGrid是不能直接获得
DataGridRow 的对象的,所以要使用LoadingRow事件来获得DataGridRow 的对象,代码如下:
private void dataGrid_LoadingRow(object sender, Microsoft.Windows.Controls.DataGridRowEventArgs e)
{
DataGridRow dataGridRow = e.Row;
CommandResultInfo dataRow = e.Row.Item as CommandResultInfo;
if (某行某列的值==某值)
{
dataGridRow.Background = Brushes.Plum;
}
}
2、隔行颜色改变
可以使用DataGrid类中的属性来实现,属性的名称为: AlternationCount="2"