title: WPF - How to get a cell from a DataGridRow?
body: <p>I have a data-bound DataGrid with alternating row background colors. I would like to color a cell differently based on the data it contains. I have tried the solution suggested by this thread </p>
  
  <p><a href="http://wpf.codeplex.com/Thread/View.aspx?ThreadId=51143" rel="noreferrer">http://wpf.codeplex.com/Thread/View.aspx?ThreadId=51143</a></p>
  
  <p>But,</p>
  
  <p>DataGridCellsPresenter presenter = GetVisualChild(row)</p>
  
  <p>always returns null.</p>
  
  <p>I am using </p>
  
  <pre><code>    public static T GetVisualChild&lt;T&gt;(Visual parent) where T : Visual
      {
          T child = default(T);
          int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
          for (int i = 0; i &lt; numVisuals; i++)
          {
              Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
              child = v as T;
              if (child == null)
              {
                  child = GetVisualChild&lt;T&gt;(v);
              }
              if (child != null)
              {
                  break;
              }
          }
          return child;
      }
  </code></pre>
  
  <p>But VisualTreeHelper.GetChildrenCount() of a DataGridRow always returns 0. I have verified that DataGridRow is not null and has been populated with data already. Any help is appreciated.</p>
  
  <p>Thanks.</p>