简体   繁体   中英

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

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

使用数据模板选择器,您将在此处找到有用的示例

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM