How to determine the index of the current ListBox from a DataTemplate?

I have a ListBox. Now I want to write a DataTemplate in such a way that the first element will have a red background and a white background for other elements. I think I need to write a DataTrigger, but I have no idea how to determine if a DataTemplate is applied to the first element.

+5
source share
1 answer
Controls

have a rotation account that you use for style

look here :

<Style TargetType="{x:Type ListBoxItem}">
    <Style.Triggers>
        <Trigger Property="ItemsControl.AlternationIndex" Value="0">
            <Setter Property="Background" Value="LightBlue"></Setter>
        </Trigger>
        <Trigger Property="ItemsControl.AlternationIndex" Value="1">
            <Setter Property="Background" Value="LightGreen"></Setter>
        </Trigger>
    </Style.Triggers>
</Style>

enjoy it!

+7
source

All Articles