title: wpf Datagrid Cell Formatting
body: <p>Being completely novice to wpf, I am trying to get a datagrid cell formatted. I've found the following code and am playing with it, however, it does not do anything.</p>
  
  <p>In this example, all I want to do is to format the columns that have a date in them. Could someone point me in the right direction???</p>
  
  <p>My datagrid source is bound to a datatable in the code behind.</p>
  
  <p>Please mindful that I may be using the wrong method to achieve my goal, so if you can advise what method  to use(in case the AutoGeneratingColumn is wrong)...</p>
  
  <p>Thanks in advance. </p>
  
  <pre><code>private void DataGridBugLog_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
  {
      Style styleCenter = new Style(typeof(DataGridCell));
      style.Setters.Add(new Setter(HorizontalAlignmentProperty, HorizontalAlignment.Center));
      style.Setters.Add(new Setter(FontWeightProperty, "Bold"));
      style.Setters.Add(new Setter(ForegroundProperty, "Red"));
  
      if (e.PropertyType == typeof(System.DateTime))
      {
          (e.Column as DataGridTextColumn).Binding.StringFormat = "dd/MM/yyyy";
          (e.Column as DataGridTextColumn).CellStyle = styleCenter;
      }
  }
  </code></pre>