I am using a ControlTemplate for my ListBoxItems for this ListBox. The ControlTemplate is style-defined and contains a rectangle whose visibility should be switched based on AlternationIndex. Although I can see how to use AlternationIndex to directly control the ListBoxItem background, I'm not sure how to use a trigger to refer to a named item in my control template. Any input is evaluated:
XAML Excerpt:
<Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid Height="84" Width="700">
<Rectangle x:Name="_listItemBg" Width="700" Height="83" Opacity="0.12">
...
I tried the following, but to no avail. The correct XAML syntax evades me:
<ControlTemplate.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Rectangle.Visibility" TargetName="_listItemBg" Value="Hidden" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Rectangle.Visibility" TargetName="_listItemBg" Value="Visible" />
</Trigger>
...
source
share