TreeView显示所选项目的蓝色

HXD*_*HXD 25 wpf xaml

我有一个树视图结构.当我尝试单击节点时,会出现一种蓝色,显示所选节点.我怎么能删除它.我不希望在树上显示选择颜色.

Viv*_*Viv 63

ItemContainerStyle在Windows-8上,方法对我不起作用.有4个画笔通常与此对应,默认模板用于TreeViewItem

键:

HighlightBrushKey - 重点背景.

HighlightTextBrushKey - 重点前景.

InactiveSelectionHighlightBrushKey - 没有焦点的背景.

InactiveSelectionHighlightTextBrushKey - 没有焦点的前景.

只要按照你认为合适的方式覆盖它们,对于你的要求,这样的事情会很好:

<TreeView>
  <TreeView.Resources>
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                      Color="Transparent" />
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
                      Color="Black" />
    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"
                      Color="Transparent" />
    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}"
                      Color="Black" />
  </TreeView.Resources>
</TreeView>
Run Code Online (Sandbox Code Playgroud)

请注意仅在您需要的范围内覆盖它们.例如,如果你把所有这些都放到App.xaml中,你会看到一些奇怪的副作用,因为使用这些画笔的所有控件现在最终都会使用被覆盖的那些,这可能不是你想要的.

  • 请注意,`SystemColors.InactiveSelectionHighlightBrushKey`和`SystemColors.InactiveSelectionHighlightTextBrushKey`仅适用于.NET 4.5或更高版本. (3认同)