var rowStyle = new Style {TargetType = typeof (DataGridRow)};
rowStyle.Setters.Add(new Setter(ForegroundProperty, Brushes.Green));
var rowTrigger = new Trigger {Property = DataGridRow.IsSelectedProperty, Value = true};
rowTrigger.Setters.Add(new Setter(ForegroundProperty, Brushes.Red));
rowTrigger.Setters.Add(new Setter(BackgroundProperty, Brushes.Orange));
rowStyle.Triggers.Add(rowTrigger);
var cellStyle = new Style {TargetType = typeof (DataGridCell)};
var cellTrigger = new Trigger {Property = DataGridCell.IsSelectedProperty, Value = true};
cellTrigger.Setters.Add(new Setter(ForegroundProperty, Brushes.Red));
cellTrigger.Setters.Add(new Setter(BackgroundProperty, Brushes.Orange));
cellStyle.Triggers.Add(cellTrigger);
datagrid.RowStyle = rowStyle;
datagrid.CellStyle = cellStyle;