ItemsControl.AlternationIndex Attached Property
Gets the assigned value of the item container when alternating item containers are used.
Assembly: PresentationFramework (in PresentationFramework.dll)
The AlternationCount and properties enable you to specify the appearance for two or more alternating item containers. For example, you can specify alternating background colors for every third item in an ItemsControl. The is assigned to each item container in the ItemsControl. begins at 0, increments until it is AlternationCount minus 1, and then restarts at 0. For example, if AlternationCount is 3 and there are seven items in the ItemsControl, the following table lists the for each item.
Position of Item in the ItemsControl
There are several methods you can use to specify different appearances for the alternating item containers. One method is to bind properties of the items container to the AlternationConverter to specify which value should be applied to the item container that has a certain value. You can also use triggers to change the value of an item container's property depending on the value of its .. You can then use an
The following example specifies that the ListBox (which inherits from ItemsControl) has alternating item containers (which are of type ListBoxItem) and specifies a different background and foreground for each one. The example binds the Background and Foreground properties to the and provides an AlternationConverter for each property.
The following example does the same as the previous example by using Trigger objects.