title: Switch control template of listview when clicking a button
body: <p>Is it possible to set the control template of my listview with xaml when I click a button?</p>
  
  <p>Right now I know how to set my contenttemplate when I have my <code>ListViewItem</code> selected, but not how to change my control template when something outside of the listview changes.</p>
  
  <p>I'd like to change my <code>ListItemTemplate</code> to use the <code>RentTemplate</code> or the <code>BuyTemplate</code> when clicking the corresponding button.</p>
  
  <pre><code>    &lt;Button x:Name="RentButton" /&gt;
      &lt;Button x:Name="BuyButton" /&gt;
  
      &lt;ListView Name="ItemsList"&gt;
          &lt;ListView.Resources&gt;
              &lt;!-- unselected item template --&gt;
              &lt;DataTemplate x:Key="DefaultItemTemplate"&gt;
              &lt;/DataTemplate&gt;
              &lt;!-- selected item template --&gt;
              &lt;DataTemplate x:Key="SelectedItemTemplate"&gt;
              &lt;/DataTemplate&gt;
              &lt;DataTemplate x:Key="RentTemplate"&gt;
              &lt;/DataTemplate&gt;
              &lt;DataTemplate x:Key="BuyTemplate"&gt;
              &lt;/DataTemplate&gt;
          &lt;/ListView.Resources&gt;
          &lt;ListView.ItemContainerStyle&gt;
              &lt;Style TargetType="ListBoxItem"&gt;
                  &lt;!-- set properties for all items --&gt;
                  &lt;Setter Property="ContentTemplate" Value="{StaticResource DefaultItemTemplate}" /&gt;
                  &lt;Style.Triggers&gt;
                      &lt;Trigger Property="IsSelected" Value="true"&gt;
                          &lt;!-- change what the selected item looks like --&gt;
                          &lt;Setter Property="ContentTemplate" Value="{StaticResource SelectedItemTemplate}" /&gt;
                      &lt;/Trigger&gt;
                  &lt;/Style.Triggers&gt;
              &lt;/Style&gt;
          &lt;/ListView.ItemContainerStyle&gt;
      &lt;/ListView&gt;
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>I'm trying to use DataTriggers to select what template to use when I change a property (which I'll change when I click my buttons). I don't think this situation is ideal, but I don't know any other way.</p>
  
  <p>The problem now is that I can't seem to mix Property triggers and DataTriggers in the same MultiTrigger.</p>
  
  <p>The scenario I'm trying to make is the following:
  If I push the <code>BuyButton</code> I want to see the <code>BuyTemplate</code>.
  Same for <code>RentButton</code> with <code>RentTemplate</code>.
  BUT when I press a third button <code>OverviewButton</code> I'd like to make a choice between two templates, depending on whether the current <code>ListBoxItem</code> is selected or not.</p>
  
  <p>Or am I misusing DataTemplates and DataTriggers and is there a better way to achieve this?</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;!-- unselected item template --&gt;
      &lt;DataTemplate x:Key="DefaultItemTemplate"&gt;
      &lt;/DataTemplate&gt;
      &lt;!-- selected item template --&gt;
      &lt;DataTemplate x:Key="SelectedItemTemplate"&gt;
      &lt;/DataTemplate&gt;
      &lt;DataTemplate x:Key="RentTemplate"&gt;
      &lt;/DataTemplate&gt;
      &lt;DataTemplate x:Key="BuyTemplate"&gt;
      &lt;/DataTemplate&gt;
      &lt;Style x:Key="ListViewItemStyle" TargetType="{x:Type ListBoxItem}"&gt;
          &lt;Style.Triggers&gt;
              &lt;MultiDataTrigger&gt;
                  &lt;MultiDataTrigger.Conditions&gt;
                      &lt;Condition Property="IsSelected" Value="false"/&gt;
                      &lt;Condition Binding="{Binding SelectedType}" Value="Overview" /&gt;
                  &lt;/MultiDataTrigger.Conditions&gt;
                  &lt;Setter Property="ContentTemplate" Value="{StaticResource DefaultItemTemplate}" /&gt;
              &lt;/MultiDataTrigger&gt;
              &lt;MultiDataTrigger&gt;
                  &lt;MultiDataTrigger.Conditions&gt;
                      &lt;Condition Property="IsSelected" Value="true"/&gt;
                      &lt;Condition Binding="{Binding SelectedType}" Value="Overview" /&gt;
                  &lt;/MultiDataTrigger.Conditions&gt;
                  &lt;Setter Property="ContentTemplate" Value="{StaticResource SelectedItemTemplate}" /&gt;
              &lt;/MultiDataTrigger&gt;
              &lt;DataTrigger Binding="{Binding SelectedType}" Value="Rent"&gt;
                  &lt;Setter Property="ContentTemplate" Value="{StaticResource RentTemplate}" /&gt;
              &lt;/DataTrigger&gt;
              &lt;DataTrigger Binding="{Binding SelectedType}" Value="Buy"&gt;
                  &lt;Setter Property="ContentTemplate" Value="{StaticResource BuyTemplate}" /&gt;
              &lt;/DataTrigger&gt;
          &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
  &lt;/Window.Resources&gt;
  </code></pre>