title: ListView: define ItemsPanelTemplate in resource dictionary
body: <p>I have a ListView which layout looks like a Windows Explorer view (icon + some details), bound to a list somewhere in the ViewModel.</p>
  
  <p>My aim here is to be able to switch between explorer view or classic view whenever we want.</p>
  
  <p>I could define an <code>ItemsPanelTemplate</code> doing exactly the work to display correctly the layout, directly in the <code>ListView.ItemsPanel</code> field. Now, I'd like to define it in the resources so that I'll be able to use it in different views, and especially in one control, the user should have the choice between Explorer view or classic list view (the default rendering for a list)</p>
  
  <p>How'd you do that? I cannot define any <code>ItemsPanelTemplate</code> in my <code>ResourceDictionary</code>, and if I define a <code>DataTemplate</code> it is not compatible (while I thought that following pure logic, <code>ItemsPanelTemplate</code> should inherit from <code>DataTemplate</code>, but it actually doesn't look like so).</p>
  
  <p>Code snippet for the actual list:</p>
  
  <p></p>
  
  <pre><code>&lt;ListView.ItemsPanel&gt;
      &lt;ItemsPanelTemplate&gt;
          &lt;WrapPanel
              Width="{Binding (FrameworkElement.ActualWidth),
                  RelativeSource={RelativeSource 
                  AncestorType=ScrollContentPresenter}}"
              ItemWidth="{Binding (ListView.View).ItemWidth,
                  RelativeSource={RelativeSource AncestorType=ListView}}"
              ItemHeight="{Binding (ListView.View).ItemHeight,
                  RelativeSource={RelativeSource AncestorType=ListView}}" 
              /&gt;
              &lt;!--
              MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"
              --&gt;
      &lt;/ItemsPanelTemplate&gt;
  &lt;/ListView.ItemsPanel&gt;
  
  &lt;ListView.ItemTemplate&gt;
      &lt;DataTemplate&gt;
          &lt;StackPanel
              Orientation="Horizontal" 
              Height="Auto" 
              Width="150" &gt;
              &lt;Image 
                  Source="{Binding Path=Appli.AppType, Converter={StaticResource TypeToIconConverter}}"
                  Margin="5"
                  Height="50"
                  Width="50" /&gt;
              &lt;StackPanel 
                  VerticalAlignment="Center"
                  Width="90" &gt;
                  &lt;TextBlock 
                      Text="{Binding Path=Appli.AppName}" 
                      FontSize="13" 
                      HorizontalAlignment="Left" 
                      TextWrapping="WrapWithOverflow"
                      Margin="0,0,0,1" /&gt;
                  &lt;TextBlock 
                      Text="{Binding Path=Appli.AppType}" 
                      FontSize="9" 
                      HorizontalAlignment="Left" 
                      Margin="0,0,0,1" /&gt;
              &lt;/StackPanel&gt;
          &lt;/StackPanel&gt;
      &lt;/DataTemplate&gt;
  &lt;/ListView.ItemTemplate&gt;
  </code></pre>
  
  <p></p>
  
  <p>Keeping the <code>ItemTemplate</code> in a static resource was easy to do, but now I can't do anything with the <code>ItemsPanelTemplate</code>...</p>
  
  <p>Any ideas? I'm using MVVM so I'm trying ideally not to use code-behind if possible</p>