views:

59

answers:

2

If I use the following in XAML I get an error:

    <Style TargetType="TreeViewItem">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Selected}" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightColor}}"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

The error is:

System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='#FF316AC5'
+3  A: 

You meant HighlightColorKey, not HighlightColor. The key is used with DynamicResource whereas the color is used only with {x:Static} but won't be dynamic.

Julien Lebosquain
I don't get the error anymore, but I don't get the highlight color either...
imekon
You probably meant <Trigger Property="IsSelected" Value="True"> as your trigger?
Julien Lebosquain
No, I wanted the DataTrigger, as it binds to Selected on my class
imekon
A: 

Looks like you were almost right, just the wrong keys!

<Style.Triggers>
    <DataTrigger Binding="{Binding Selected}" Value="True">
        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
    </DataTrigger>
</Style.Triggers>
imekon