title: How can I bind a DataGridTemplateColumn to column value instead of row value?
body: <p>I have a property grid control that has many cell editors that automatically gets applied using a <code>CellEditorTemplateSelector</code>. Each property grid row is bound against a simple PropertyItemViewModel. </p>
  
  <p>Now, I'm trying to reuse all these cell editors and present it in a DataGrid to be able to compare multiple object values side by side. So I added a <code>PropertiesRow</code> object that contains a list of <code>PropertyItemViewModel</code> (same as the above property grid).</p>
  
  <p>To present each cell, I have a simple data template that uses the same template selector as the property grid.</p>
  
  <pre><code>&lt;DataTemplate x:Key="CellDataTemplate"&gt;
      &lt;ContentControl
           Content="{Binding Mode=OneWay}"
           ContentTemplateSelector="{StaticResource CellEditorTemplateSelector}" /&gt;            
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>However, for this to work, the template expects a <code>PropertyItemViewModel</code> (not the PropertiesRow), so I have to somehow feed it through a binding that fetches the correct one from <code>PropertiesRow.PropertyItems[columnIndex]</code>. So when I add the columns through the code, I tried something like this:</p>
  
  <pre><code>void AddColumns()
  {
      foreach (Property shownProperty in _ShownProperties)
      {
          _DataGrid.Columns.Add(new DataGridTemplateColumn()
          {
              Header = shownProperty.Name;
              Binding = new Binding("PropertyItems[" + index + "]");
              CellTemplate = (DataTemplate) FindResource("CellDataTemplate");
          });
      }
  }
  </code></pre>
  
  <p>However, <code>DataGridTemplateColumn</code> does not have a Binding property! So I tried to generate an intermediate DataTemplate for each column, but that is starting to be very complex, and I feel there must be a simpler way of doing this.</p>
  
  <p>Any suggestions? </p>