如何为TreeViewItem覆盖SelectedUnfocusedColor

墨菲斯托123

我正在将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}用于此颜色,因此我尝试通过<Color>在TreeView的“资源”部分中放置所需的颜色来覆盖它-没有帮助。

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

我没有主意,Google并没有提供太多帮助(我没有尝试过的唯一其他主意是完全重新设计TreeViewItem,考虑到默认模板的大小,这似乎有些过头了。

毫米8

默认模板使用,SystemColors.InactiveSelectionHighlightBrushKey因此您应该“覆盖”此笔刷:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章