WPF Resource Not Found

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>

Error:

System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='#FF316AC5'
+3
source share
2 answers

Looks like you were almost right, only 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>
+2
source

You mean HighlightColorKey, not HighlightColor. The key is used with DynamicResource, while the color is used only with {x:Static}, but will not be dynamic.

+5
source

Source: https://habr.com/ru/post/1746186/


All Articles