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