title: How to dynamically change a WPF control's template using a checkbox?
body: <p>I have an error dialog (shown simplified below).  </p>
  
  <p>I display the <em>Report</em> object in a <em>ContentControl</em> to which I have defined a <em>Template</em>  <em>simpleErrorTemplate</em>.  </p>
  
  <p>There is a <em>CheckBox</em> on the Window that I would like to use to change the template to/from <em>detailedErrorTemplate</em>.  What is the best way to achieve this?</p>
  
  <pre><code>&lt;Window x:Class="Core.ErrorDialog"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
      &lt;Window.Resources&gt;
  
          &lt;ControlTemplate x:Key="simpleErrorTemplate"&gt;
              &lt;TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="{Binding Message}" /&gt;
          &lt;/ControlTemplate&gt;
  
          &lt;ControlTemplate x:Key="detailedErrorTemplate"&gt;
              &lt;TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="{Binding Message}" /&gt;
              &lt;TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="{Binding Details}" /&gt;
              &lt;TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="{Binding StackTrace}" /&gt;
          &lt;/ControlTemplate&gt;
  
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="*" /&gt;         
              &lt;RowDefinition Height="50" /&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;ContentControl Grid.Row="0" Template="{StaticResource simpleErrorTemplate}" DataContext="{Binding Report}"/&gt;
  
          &lt;CheckBox Margin="10,0,0,0" Grid.Row="1" x:Name="ChkShowDetails"&gt;Show Details&lt;/CheckBox&gt;            
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>