I have a ListboxItem style defined as:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style x:Key="VoidwalkerListBoxItem" TargetType="ListBoxItem"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Border Name="_itemContainer" Padding="0" BorderBrush="Transparent" BorderThickness="1" SnapsToDevicePixels="true"> <ContentPresenter /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter TargetName="_itemContainer" Property="BorderBrush" Value="{DynamicResource VoidwalkerBorderBrush}" /> <Setter TargetName="_itemContainer" Property="Background" Value="Red" /> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="_itemContainer" Property="BorderBrush" Value="{DynamicResource VoidwalkerBorderBrush}" /> </Trigger> <Trigger Property="ItemsControl.AlternationIndex" Value="0"> <Setter Property="Foreground" Value="{DynamicResource VoidwalkerForegroundBrush}" /> <Setter TargetName="_itemContainer" Property="Background" Value="{DynamicResource VoidwalkerContextBrush}" /> </Trigger> <Trigger Property="ItemsControl.AlternationIndex" Value="1"> <Setter Property="Foreground" Value="{DynamicResource VoidwalkerForegroundBrush}" /> <Setter TargetName="_itemContainer" Property="Background" Value="{DynamicResource VoidwalkerControlBrush}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>
Essentially, what I'm trying to do is alternate the background colors of every other element that works. Here is the image:

However, the problem arises when I want to color the selected background of the element, in this case I chose Red for testing purposes, as well as a gray brush. Here is the result:

As you can see, I selected "Item 009", but the background has not been changed to red. The only thing that has changed is the color of the border. If I disable the AlternationIndex trigger, the background will be colored correctly. This leads me to believe that for some reason, the AlternationIndex trigger has priority over IsSelected Trigger or fired after IsSelected Trigger, so I don't see a red background.
My question is: how can I fix my implementation to get around this apparent redefinition of the IsSelected trigger, by coloring my background in red, while preserving the desired AlternationIndex color?
c # wpf xaml
Krythic Oct 30 '17 at 0:31 2017-10-30 00:31
source share