title: ItemTemplateSelector in WPF Datagrid with AutoGenerateColumns
body: <p>In our data grid we're using an <code>ItemTemplateSelector</code> to switch between two data templates based on the data bound to a particular cell.</p>
  
  <p>As the number of columns depends on the current data set we're using <code>AutoGenerateColumns</code> in our <code>DataGrid</code>.</p>
  
  <p>It appears that this particular combination does not work well -<br>
  the template selector isn't even called.</p>
  
  <p><strong>Can we use the template selector in a data grid where columns are created automatically?</strong></p>
  
  <p>More specifically: Is this possible using <em>XAML only</em> w/o putting logic into the code-behind file or using custom behaviours?</p>
  
  <p>Our <strong>data grid definition</strong> is fairly trivial:</p>
  
  <pre><code> &lt;DataGrid
       ItemTemplateSelector="{StaticResource myCustomDataTemplateSelector}"
       ItemsSource="{Binding MyData}"&gt;
       &lt;DataGrid.Columns&gt;
       &lt;/DataGrid.Columns&gt;
   &lt;/DataGrid&gt;
  </code></pre>
  
  <p>The <strong>item template selector definition</strong>:</p>
  
  <pre><code>&lt;UserControl.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;helpers:CustomDataTemplateSelector x:Key="myCustomDataTemplateSelector"/&gt;
      &lt;/ResourceDictionary&gt;
  &lt;/UserControl.Resources&gt;
  </code></pre>