首页 > 解决方案 > 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>

标签: c#wpf

解决方案


推荐阅读