title: DataGrid CellTemplate multiple properties
body: <p>I have a DataGrid with a CellTemplate where I create columns dynamically via PropertyDescriptors. I'm using this approach: <a href="http://paulstovell.com/blog/dynamic-datagrid" rel="nofollow">http://paulstovell.com/blog/dynamic-datagrid</a> Column generation works, and the correct content reaches the correct cell.</p>
  
  <p>My problem lies when i changes the content provided to the cell from ex. 'string' or 'int' to a custom class containing multiple properties. The CellTemplate wont bind to the properties within the contentclass.</p>
  
  <p>The Content class:</p>
  
  <pre><code>    public class ContentWrapper
      {
          public Color Color{ get; set; }
          public String Text { get; set; }
          public String Comment { get; set; }
      }
  </code></pre>
  
  <p>The cellTemplate:</p>
  
  <pre><code>    &lt;DataGrid.Resources&gt;
          &lt;Style TargetType="{x:Type DataGridCell}"&gt;
              &lt;Setter Property="Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="{x:Type DataGridCell}"&gt;
                          &lt;Grid ToolTip="{Binding Comment}"
                                Background="{Binding Color, Converter={StaticResource ColorToBrushConverter}}"&gt;
                              &lt;TextBlock Text="{Binding Text}"
                                         VerticalAlignment="Bottom"
                                         HorizontalAlignment="Left"/&gt;                                                                
                              &lt;Polygon Visibility="{Binding Comment, Converter={StaticResource CommentVisibleConverter}, FallbackValue=Hidden}"
                                       HorizontalAlignment="Right"
                                       Points="0,0 6,0 6,6"
                                       VerticalAlignment="Top"&gt;
                                  &lt;Polygon.Fill&gt;
                                      &lt;SolidColorBrush Color="Red" /&gt;
                                  &lt;/Polygon.Fill&gt;
                              &lt;/Polygon&gt;
                          &lt;/Grid&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
      &lt;/DataGrid.Resources&gt;
  </code></pre>
  
  <p>How do i make the CellTemplate able to support a custom class and bind to it's properties?
  Or is there a more easy way?</p>
  
  <p><strong>EDIT</strong>
  The Column generation is this:</p>
  
  <pre><code>    private void OnAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
      {
          var property = e.PropertyDescriptor as Property;
          if (property != null)
          {
              var binding = new Binding() { Path = new PropertyPath(property), Mode = property.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay };
              var dataGridBoundColumn = e.Column as DataGridBoundColumn;
              if (dataGridBoundColumn != null)
                  dataGridBoundColumn.Binding = binding;
              else
              {
                  var dataGridComboBoxColumn = e.Column as DataGridComboBoxColumn;
                  if (dataGridComboBoxColumn != null)
                      dataGridComboBoxColumn.SelectedItemBinding = binding;
              }
          }
      }
  </code></pre>