title: WPF dataGrid (or ListView) filled via Binding, different Template for Rows
body: <p>I have a WPF dataGrid which is filled via DataBinding. This list contains different columns. I have two types of rows, one type contains all the columns in the rows, and the other should span one column over all the columns.</p>
  
  <p>Is there a easy way to make this possible? (maybe use a ListView instead of a DataGrid?)</p>
  
  <p>I attached a screenshot how it should look like:</p>
  
  <p><img src="https://i.stack.imgur.com/jQcbH.png" alt="enter image description here"></p>
  
  <p>I now tried with Item Template Selector:</p>
  
  <p>My templates in the Resources (The two templates are not correct, but they are only for testing!)</p>
  
  <pre><code>    &lt;DataTemplate x:Key="commentTemplate"&gt;
          &lt;TextBlock Text="{Binding}"/&gt;
      &lt;/DataTemplate&gt;
  
      &lt;DataTemplate x:Key="normalTemplate"&gt;
          &lt;Image Source="{Binding }" /&gt;
      &lt;/DataTemplate&gt;
  
      &lt;WPFVarTab:VarTabRowItemTemplateSelector 
          NormalRowsTemplate="{StaticResource normalTemplate}" 
          CommentRowsTemplate="{StaticResource commentTemplate}" 
          x:Key="vartabrowItemTemplateSelector" /&gt;
  </code></pre>
  
  <p>and my Datagrid:</p>
  
  <pre><code>&lt;DataGrid AutoGenerateColumns="False" Margin="0,22,0,22" 
                Name="dataGrid" Grid.RowSpan="2" CanUserAddRows="True"
                RowBackground="Azure" AlternatingRowBackground="LightSteelBlue"
                ItemTemplateSelector="{StaticResource vartabrowItemTemplateSelector}" &gt;
  </code></pre>
  
  <p>and my Template Selector:</p>
  
  <pre><code>public class VarTabRowItemTemplateSelector : DataTemplateSelector 
  {
      public DataTemplate NormalRowsTemplate { get; set; }
      public DataTemplate CommentRowsTemplate { get; set; }
  
      public override DataTemplate SelectTemplate(object item, DependencyObject container)
      {
          S7VATRow vRow = item as S7VATRow;
          if (vRow == null || string.IsNullOrEmpty(vRow.Comment))
              return NormalRowsTemplate;
          return CommentRowsTemplate;
      }
  }
  </code></pre>
  
  <p>I put a stop in the first row in SelectTemplate but this is never called!</p>