【问题标题】:Windows Phone 8: Alternating colors on a ItemsControlWindows Phone 8:ItemsControl 上的交替颜色
【发布时间】:2014-04-28 07:34:50
【问题描述】:

我想根据项目索引更改 ItemsControl 中项目的颜色 - 奇数或偶数。我发现here 很容易做到,但看起来 Windows Phone 的 ItemsControl 没有 AlternationCount 属性。

是否有任何替代 AlternationCount 属性或解决方法来实现所需的行为?

ItemsControl reference

【问题讨论】:

    标签: c# xaml windows-phone-8


    【解决方案1】:

    您可以继承 ItemsControl 类并覆盖 PrepareContainerForItemOverride。在那里你可以计算 AlternationIndex 例如通过使用 ItemsControl.IndexFromContainer。现在您可以将特定样式应用到容器或设置附加属性。

    【讨论】:

      【解决方案2】:

      使用数据模板选择器,你会发现有用的样本here

      【讨论】:

      • 这不是一个解决方案,因为它依赖于模型数据作为应指定的项目类型,而不是 ItemsControl 中的项目索引。
      猜你喜欢
      • 2011-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-27
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 2011-07-04
      相关资源
      最近更新 更多