Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change highlight color in hierarchical TreeView

I have got a TreeView with a HierarchicalDataTemplate.

<HierarchicalDataTemplate x:Key="treeViewItemTemplate" ItemsSource="{Binding GetChildren}">
    <DockPanel Margin="0,8,8,0">
        <Image Source="{Binding GetImage}" Width="16" Height="16" />
        <local:MonitorTriStateCheckBox Margin="4,0,0,0" IsChecked="{Binding IsChecked}" Click="CheckBox_Clicked" Tag="{Binding UniqueKey}" Style="{DynamicResource CheckBox}"></local:MonitorTriStateCheckBox>
        <TextBlock Margin="4,0,0,0" Text="{Binding Name}" Style="{DynamicResource TextBlock}">
        </TextBlock>
    </DockPanel>
    <HierarchicalDataTemplate.Triggers>
        <Trigger Property="TreeViewItem.IsSelected" Value="True">
            <Setter Property="TreeViewItem.Background" Value="Orange" />
        </Trigger>
    </HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>

As you can see in the code, i set the is selected Trigger of the TreeViewItem, but this has no effect. I alos tried this:

<TreeView.ItemContainerStyle>
    <Style TargetType="{x:Type TreeViewItem}">
        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
        <Setter Property="Visibility" Value="{Binding IsVisible, Mode=TwoWay}" />
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="Orange" />
            </Trigger>
        </Style.Triggers>
    </Style>
</TreeView.ItemContainerStyle>

But that had no effect either.

Has anyone got an idea what to do, to change the hightlight color of a TreeViewItem?

like image 497
flurreh Avatar asked Dec 28 '22 20:12

flurreh


1 Answers

Try this...

<TreeView.Resources>                                                
    <SolidColorBrush Color="Green" x:Key="{x:Static SystemColors.HighlightBrushKey}"/>
</TreeView.Resources>
like image 109
Olga Avatar answered Jan 16 '23 06:01

Olga