C# 如何覆盖TreeViewItem的SelectedInfocusedColor

C# 如何覆盖TreeViewItem的SelectedInfocusedColor,c#,wpf,xaml,.net-core,C#,Wpf,Xaml,.net Core,我正在将我的WPF应用程序从.NET Framework迁移到.NET Core 3.0 之前,我使用了以下“hack”来覆盖TreeViewItem的选定非聚焦背景色: <TreeView.ItemContainerStyle> <Style TargetType="TreeViewItem"> <Style.Resources> <SolidColorBrush x:Key="{x:Static Sys

我正在将我的WPF应用程序从.NET Framework迁移到.NET Core 3.0

之前,我使用了以下“hack”来覆盖TreeViewItem的选定非聚焦背景色:

<TreeView.ItemContainerStyle>
    <Style TargetType="TreeViewItem">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>
        </Style.Resources>
    </Style>
</TreeView.ItemContainerStyle>

但它在.NETCore3.0中不起作用:未聚焦的选定项仍有浅灰色背景

MSDN中的默认模板使用此颜色的
{StaticResource selectednfoccusedcolor}
,因此我尝试通过在树视图的参考资料部分放置所需的
来覆盖它-这没有帮助

我还尝试在Style.Triggers for TreeViewItem样式中创建
,当IsSelected为True时,将背景色设置为
{x:Static SystemColor.HighlightColor}
,但也没有帮助


我没有想法,谷歌也没有提供太多帮助(我唯一没有尝试的另一个想法是完全重新部署TreeViewItem,考虑到默认模板的大小,这似乎有点过分了。

默认模板使用
SystemColor.InactiveSelectionHighlightBrushKey
,所以你应该“覆盖”这个笔刷:

<Style TargetType="TreeViewItem">
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>
    </Style.Resources>
</Style>


您使用的是哪个版本的.NET Core 3.0?最新版本,preview3。@mephisto123:您是否尝试使用
SystemColor的
x:Key
定义
SolidColorBrush
资源。InactiveSelection HighlightBrushKey
?它可以工作!非常感谢!请将其作为答案发布,以便我可以将其标记为正确的:)