簡體   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