3

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

Community
  • 1
  • 1
Anthony
  • 2,264
  • 5
  • 23
  • 29

2 Answers2

1

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.

HDW Production
  • 1,402
  • 10
  • 13
1

Use data template selector, you will find useful sample here

DOTNET Team
  • 3,391
  • 17
  • 30
  • This is not a solution because it relies on Model data as item Type which should be specified, but not on item index in ItemsControl. – Anthony Apr 28 '14 at 09:40