Anthony
Anthony

Reputation: 2824

Windows Phone 8: Alternating colors on a ItemsControl

I want to alternate color of items in ItemsControl based on item index - odd or even. As I found here it is pretty easy to do, but looks like ItemsControl for Windows Phone doesn't have AlternationCount property.

Is there any alternatives to AlternationCount property or workarounds to achieve required behavior?

ItemsControl reference

Upvotes: 3

Views: 240

Answers (2)

user3497034
user3497034

Reputation:

Use data template selector, you will find useful sample here

Upvotes: 1

HDW Production
HDW Production

Reputation: 1402

You could inherit the ItemsControl class and override PrepareContainerForItemOverride. There you can calculate the AlternationIndex e.g. by using ItemsControl.IndexFromContainer. Now you can apply a specific Style to the container or set an attached property.

Upvotes: 1

Related Questions