0

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>
pewex
  • 51
  • 8
  • I have tried with both normal trigger and data trigger. If i use normal trigger i get no background colour – pewex Jul 31 '20 at 08:41
  • `{RelativeSource AncestorType=ListBoxItem}` – Sinatr Jul 31 '20 at 08:43
  • @Sinatr Set property 'System.Windows.Data.RelativeSource.Mode' threw an xaml exception.' I am getting exeception for the Mode. If i removed the mode showing can't recoginize the ItemsControl.AlternationIndex. – pewex Jul 31 '20 at 08:47
  • Just hit `F5`. Designer is often shows errors until you rebuild. – Sinatr Jul 31 '20 at 08:48
  • @Sinatr Thanks I have got the expected output with this – pewex Jul 31 '20 at 08:57

0 Answers0