title: Add an image to a bound datagrid
body: <p>I have a datagrid that is databound, but before the binding happens, I use the datagrid loadingrow event handler to colour the background of each row depending on the condition met.  I want to remove this and I have decided to add a datatemplatecolumn (STATUS) to the datagrid which is not bound but I am hoping to populate with an appropriate image depending on the condition met using LoadingRow event.  The reason I am not using a DataTemplate is due to the date comparison that is required to determine the correct iamge. </p>
  
  <p>I have looked at several examples but have no idea how to add the image to the cell on the Status column to include an image for each row.  I would be extremely grateful for some guidance.</p>
  
  <p>Thanks for your help as always,</p>
  
  <p>XAML</p>
  
  <pre><code>&lt;DataGrid AutoGenerateColumns="False" x:Name="schDataGrid" IsReadOnly="True" LoadingRow="schDataGrid_LoadingRow" CanUserAddRows="False"&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTemplateColumn Header="STATUS" /&gt;  &lt;-- Add Image Here --&gt;
          &lt;DataGridTextColumn Binding="{Binding ITEMNUMBER}" Header="ITEMNUMBER" /&gt;
          &lt;DataGridTextColumn Binding="{Binding CODE}" Header="CODE" /&gt;
          &lt;DataGridTextColumn Binding="{Binding DESC}" Header="STD DESCRIPTION" /&gt;
          &lt;DataGridTextColumn Binding="{Binding DESCRIPTION}" Header="UNIQUE DESCRIPTION" /&gt;
          &lt;DataGridTextColumn Binding="{Binding SERIALNUMBER}" Header="SERIAL NUMBER" /&gt;
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>C#</p>
  
  <pre><code>private void schDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
      {
              var row = e.Row;
              DataRowView rView = row.Item as DataRowView;
              string DUEDATE = rView["DUEDATE"].ToString();
  
              DateTime now = Convert.ToDateTime(DateTime.Now.ToString("dd/MM/yyyy"));
              DateTime compareDate = Convert.ToDateTime(DUEDATE);
              TimeSpan difference = now - compareDate;
  
              if (difference.Days &lt;= 0)
              {
                  Image image = new Image();
                  var uriSource = new Uri(@"/main;component/Images/Icons/green.gif", UriKind.Relative);
                  image.Source = new BitmapImage(uriSource);
  
                  //Now Add the image to the DataGridTemplateColumn["STATUS"]
                  rItem["STATUS"] = image;
              }
  </code></pre>