title: How to set the background color of a DataGrid row in code behind?
body: <p>I create a <code>DataGrid</code> object in my code behind and set the content with <code>obj.ItemsSource</code>.</p>
  
  <p>Now I would like to set the background color of one specific row in the code behind. How can I achieve this?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I create the <code>DataGrid</code> object in the code behind like following:</p>
  
  <pre><code>var dataGrid = new DataGrid();
  dataGrid.ItemsSource = BuildDataGrid(); // Has at least one row
  var row = (DataGridRow) dataGrid.ItemContainerGenerator.ContainerFromIndex(0);
  row.Background = Brushes.Red;
  </code></pre>
  
  <p>But the <code>row</code> object is <code>null</code>. Why is that?</p>