繁体   English   中英

如何覆盖 TreeViewItem 的 SelectedUnfocusedColor

[英]How to override SelectedUnfocusedColor for TreeViewItem

我正在将我的 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>

但它在 .NET Core 3.0 中不起作用:未聚焦的选定项仍然具有浅灰色背景。

MSDN 中的默认模板为此颜色使用{StaticResource SelectedUnfocusedColor} ,因此我尝试通过在 TreeView 的 Resources 部分放置所需的<Color>来覆盖它 - 它没有帮助。

我还尝试在 Style.Triggers 中为 TreeViewItem 样式创建一个<Trigger> ,当 IsSelected 为 True 时将背景颜色设置为{x:Static SystemColors.HighlightColor} ,但它也没有帮助。

我没有想法,Google 没有提供太多帮助(我没有尝试的唯一其他想法是完全重新模板化 TreeViewItem,考虑到默认模板的大小,这似乎有点矫枉过正。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM