title: How to change ListBox DataTemplate in WPF based on CheckBox
body: <p>I am trying to apply a <code>DataTrigger</code> to change the <code>DataTemplate</code> for a <code>ListBox</code> and am getting the error:</p>
  
  <p><code>"Error 1   Cannot find the Trigger target 'IssueListBox'.  (The target must appear before any Setters, Triggers, or Conditions that use it.)"</code></p>
  
  <p>I have a <code>ListBox</code> in my main <code>Window</code> (In a <code>DockPanel</code> along with other controls):</p>
  
  <pre><code>&lt;ListBox x:Name="IssueListBox"
    ItemsSource="{Binding}"
      ItemTemplate="{StaticResource ShowIssueSimple}" 
      IsSynchronizedWithCurrentItem="True"
      HorizontalContentAlignment="Stretch" 
      BorderThickness="3" DockPanel.Dock="Top" 
      VerticalContentAlignment="Stretch" Margin="2"/&gt;
  </code></pre>
  
  <p>I have a pair of <code>DataTemplate</code>s in App.xaml with a <code>DataTrigger</code> at the bottom of the 2nd template:</p>
  
  <pre><code>    &lt;DataTemplate x:Key="ShowIssueDetail"&gt;
          &lt;Border CornerRadius="4, 8, 4, 8" Margin="2" MinWidth="400" BorderThickness="3" 
                  BorderBrush="{Binding Path=IssUrgency, Converter={StaticResource IntToRYGBBoarderBrushConverter}}"&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                   &lt;StackPanel Margin="10"&gt;
                      &lt;TextBlock Text="{Binding IssSubject}" FontWeight="Bold" FontSize="14"/&gt;
                      &lt;StackPanel Width="Auto" Orientation="Horizontal"&gt;
                          &lt;TextBlock Text="Due: " FontWeight="Bold"/&gt;
                          &lt;TextBlock Text="{Binding IssDueDate}" FontStyle="Italic" HorizontalAlignment="Left"/&gt;
                      &lt;/StackPanel&gt;
                      &lt;StackPanel Width="Auto" Orientation="Horizontal"&gt;
                          &lt;TextBlock Text="Category: " FontWeight="Bold"/&gt;
                          &lt;TextBlock Text="{Binding IssCategory}"/&gt;
                      &lt;/StackPanel&gt;
                  &lt;/StackPanel&gt;
              &lt;/StackPanel&gt;
          &lt;/Border&gt;
      &lt;/DataTemplate&gt;
  
      &lt;DataTemplate x:Key="ShowIssueSimple"&gt;
  
          &lt;Border CornerRadius="6" 
                  Margin="2,1,2,1"
                  MinWidth="400"
                  BorderThickness="2" 
                  SnapsToDevicePixels="True"
                  BorderBrush="{Binding Path=IssUrgency, Converter={StaticResource IntToRYGBBoarderBrushConverter}}"&gt;
              &lt;StackPanel Margin="5"&gt;
                  &lt;TextBlock Text="{Binding IssSubject}" FontWeight="Bold" FontSize="14"/&gt;
              &lt;/StackPanel&gt;
          &lt;/Border&gt;
          &lt;DataTemplate.Triggers&gt;
              &lt;DataTrigger Binding="{Binding Source={StaticResource sbvm}, Path=ShowDetailListItems}" Value="True"&gt;
                  &lt;Setter TargetName="IssueListBox" Property="ItemTemplate" Value="{StaticResource ShowIssueDetail}"/&gt;
              &lt;/DataTrigger&gt;
          &lt;/DataTemplate.Triggers&gt;
      &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>How do I get the <code>Trigger</code> to work? Mr Google has failed me, many examples like this abound but they are not based on another control.</p>