Simple but important feature which really help us in real-time applications.Giving different look and feel or colors to alternate rows helps users to differentiate two consecutive rows in a ListBox or ListView.Basically controls which are derived from ItemsControl.
Below xaml code shows how alternate colors are applied into a ListBox
Xaml code to create ListBox with 6 items
Xaml code of the Style which has the alternate style support.Note the change is in the ItemContainerStyle.Here Style is applied to ListBoxItem
When we run it shows as follows
Here the ItemsControl has got most of the implementation part.It has some members which control the behavior of alternate style.The attached property ItemsControl.AlternationIndex tells the index and according to that we can change color or anything through style.
The Alternation count specifies the frequency.Below code uses 3 as ItemsControl.AlternationCount.See the difference.
Style supports AlternationCount=3
I don't think a sample is needed.