c# - Changing the style of a border inside data template for the listbox item based on the alterationindex
问题描述
I am trying to change the border background color for the element inside a grid in the data template of listitemtemplate. I have tried using the datatrigger inside the border to access the listboxitem alterationindex. I have set the alteration count in the listbox. The border is inside the grid. But my output is completely red, not red and green. May i know how to achieve this?
I have checked with the How to use AlternationIndex in ItemsControls?
But it didn't help me
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=(ItemsControl.AlternationIndex)}" Value="0">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=(ItemsControl.AlternationIndex)}" Value="1">
<Setter Property="Background" Value="Green"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
解决方案
推荐阅读
- generics - 通用类类型 IDE 警告的未经检查的强制转换
- git - 没有 tty 时如何阻止 git 打包标签注释?
- mongodb - 在聚合管道阶段以公里为单位计算点到点的距离
- ionic-framework - Ionic 3 angularfire2 打印出 [object Object] 数据
- vhdl - VHDL:无法将任何内容分配给整数数组输出端口
- angular - 无法在 this.afAuth.authState.subscribe() 方法之外读取 uid,在我重新加载页面后显示 uid undefined
- email - 如何使用 dovcot 在 directadmin 中加密来保护 mail.domain.com?
- c++ - 搜索字符串的文本
- php - 如何解决未定义的变量:category_datails
- json - 如何在 Swift 中解码具有许多唯一键的嵌套 JSON?