How to set 2 color background to a TreeView
Posted: 23 Jan 2025, 11:19
Hi,
It's not working the way I expect it to. Each nested TreeViewItem starts with AlternationIndex = 0.
Can you tell me how to implement indexing of all expanded TreeViewItems?
Code: Select all
<AlternationConverter x:Key="Converter.AlternationRows">
<SolidColorBrush>#00333333</SolidColorBrush>
<SolidColorBrush>#FF282828</SolidColorBrush>
</AlternationConverter>
<Style TargetType="TreeViewItem">
<Setter Property="AlternationCount" Value="2"/>
<Setter Property="Background"
Value="{Binding Path=(ItemsControl.AlternationIndex),
RelativeSource={RelativeSource Self}, Converter={StaticResource Converter.AlternationRows}}" />
</Style>
<TreeView AlternationCount="2"/>Can you tell me how to implement indexing of all expanded TreeViewItems?