When writing ListBoxItem triggers in a style that trigger on the ListBox.AlternationIndex attached property value, if you use the valid syntax ListBox.AlternationIndex like the first trigger below, the designer will display the following error:
Error Property 'AlternationIndex' was not found in type 'ListBox'…
The workaround is to use the alternate valid syntax ItemsControl.AlternationIndex as the second trigger below does.
<Style x:Key="alternatingWithTriggers" TargetType="{x:Type ListBoxItem}"> <Setter Property="Background" Value="Blue"/> <Setter Property="Foreground" Value="White"/> <Style.Triggers> <!-- valid XAML but does not work in the designer and causes an error --> <Trigger Property="ListBox.AlternationIndex" Value="1"> <Setter Property="Background" Value="CornflowerBlue"/> <Setter Property="Foreground" Value="Black"/> </Trigger> <!-- valid alternate XAML that works in the designer --> <Trigger Property="ItemsControl.AlternationIndex" Value="2"> <Setter Property="Background" Value="LightBlue"/> <Setter Property="Foreground" Value="Navy"/> </Trigger> </Style.Triggers> </Style>
Microsoft values your opinion about our products and documentation. In addition to your general feedback it is very helpful to understand:
Thank you for your feedback and have a great day,
Karl Shifflett Visual Studio Cider Team