I have multiple DataGrids bound to DataTables, which are dynamically created using SQL. Whenever DataTable records change (add, modify, delete), the DataGridCells shall chan
For completeness:
If you really intend to change the color at runtime, disregarding MVVM you can for instance use DataGrid_LoadingRow, check for it's DataContext (in this case a DataRowView) and go on from there:
// Changes beeing made to the entire row in this case
private void DgModules_LoadingRow(object sender, DataGridRowEventArgs e)
{
DataGridRow gridRow = e.Row;
DataRow row = (gridRow.DataContext as DataRowView).Row;
switch (row.RowState)
{
case DataRowState.Added:
gridRow.Background = new SolidColorBrush(Colors.Green);
break;
case DataRowState.Modified:
gridRow.Background = new SolidColorBrush(Colors.Yellow);
break;
case DataRowState.Deleted:
gridRow.Background = new SolidColorBrush(Colors.Red);
break;
}
}
If you wanna approach this actually using MVVM, go for this solution.