开发者

WPF resource not found

开发者 https://www.devze.com 2022-12-31 01:42 出处:网络
If I use the following in XAML I get an error: <Style TargetType=\"TreeViewItem\"> <Style.Triggers开发者_如何学JAVA>

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

    <Style TargetType="TreeViewItem">
        <Style.Triggers开发者_如何学JAVA>
            <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'


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.


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消