2017-07-01 129 views
0

我使用DataGrid并需要更改一行的背景颜色。 DataGrid使用滚动,当我尝试此代码时,背景也滚动。在运行时更改Datagrid wpf中的行的背景颜色

DataGridRow row = (DataGridRow)gg.ItemContainerGenerator.ContainerFromIndex(i);     
row.Background = Brushes.Red; 
+2

有关GUI方面改变的东西,我建议你使用WPF数据绑定 – Tony

回答

0

有事件被称为“LoadingRow通知”,要求当行加载到GridView你可以在那里把你的条件,如:

private void table_LoadingRow(object sender, DataGridRowEventArgs e) 
    { 
     if (((MyData)e.Row.DataContext).Module.Trim().Equals("SomeText")) 
     { 
      e.Row.Foreground = new SolidColorBrush(Colors.Red); 
     } 
    }