Question

I am trying to change the background of the TreeViewItems in a TreeView, based on an a property (boolean) attached to the TreeViewItems. I've tried this :

    <local:BooleanToBrushConverter x:Key="BooleanToBrushConverter" 
                                   TrueBrush="Yellow" FalseBrush="Transparent"/>


    <local:TreeViewEx ItemsSource="{Binding Items}">

        <TreeView.ItemContainerStyle>
            <Style TargetType="{x:Type TreeViewItem}">
                <Setter Property="IsExpanded" Value="True"/>
                <Setter Property="Background" Value="{Binding Path=(local:TreeViewItemExtensions.Selected), 
                                                              RelativeSource={RelativeSource Self},
                                                              Converter={StaticResource BooleanToBrushConverter}}"/>
        <TreeView.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Green"/>
        </TreeView.Resources>

        ...

    </local:TreeViewEx>

Ran the app, but although I've (programatically) set the property (Selected, not to be confused with IsSelected) to true on the "Child" TreeViewItem the background was not set

I've taken a look with Snoop and found that it doesn't have the yellow background as it should (the converter fires and returns correctly) :

enter image description here

However, taking a peek in Snoop it shows that the Yellow brush has been applied to that TreeViewItem :

enter image description here

However if I manually set the background to the parent Stackpanel ([016] in Snoop) it reflects that value. But I can't get to it by the style..

Any ideas?


UPDATE : It seems that the currently selected item has some kind of style that needs addressing somehow..

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top