【发布时间】:2014-04-28 07:34:50
【问题描述】:
我想根据项目索引更改 ItemsControl 中项目的颜色 - 奇数或偶数。我发现here 很容易做到,但看起来 Windows Phone 的 ItemsControl 没有 AlternationCount 属性。
是否有任何替代 AlternationCount 属性或解决方法来实现所需的行为?
【问题讨论】:
标签: c# xaml windows-phone-8
我想根据项目索引更改 ItemsControl 中项目的颜色 - 奇数或偶数。我发现here 很容易做到,但看起来 Windows Phone 的 ItemsControl 没有 AlternationCount 属性。
是否有任何替代 AlternationCount 属性或解决方法来实现所需的行为?
【问题讨论】:
标签: c# xaml windows-phone-8
您可以继承 ItemsControl 类并覆盖 PrepareContainerForItemOverride。在那里你可以计算 AlternationIndex 例如通过使用 ItemsControl.IndexFromContainer。现在您可以将特定样式应用到容器或设置附加属性。
【讨论】:
使用数据模板选择器,你会发现有用的样本here
【讨论】: