TreeView显示所选项目的蓝色

时间:2013-07-23 15:19:00

标签: wpf xaml

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

1 个答案:

答案 0 :(得分:58)

在Windows-8上,

ItemContainerStyle方法对我说不起作用。有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>

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