tags:

views:

25

answers:

1

Is it possible to get this row coloring in the WPF Listbox?

White
LightGray
Gray
White
LightGray
etc.?

Thanks

+1  A: 

Hi,

Yes it's possible. You can use the AlternationCount Property of the ListBox. Something like

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

And then just set the AlternationCount on your ListBox

<ListBox AlternationCount="3"
         ...>
Meleak
Thanks, that did the trick. But I have 2 Listboxes in the same form, both get this and both of the Listboxes gets this coloring
This style is targetting ListBoxItem so it will applicable to all the listbox.
Kishore Kumar
Ok, got it working. Thanks again