我有一个树形结构。当我尝试点击节点时,会显示选定节点的蓝色颜色。如何移除它? 我不想在树上显示选定节点的颜色。
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>
一定要注意只在需要的范围内覆盖它们。例如,如果您将所有内容放入App.xaml中,则会看到一些奇怪的副作用,因为使用这些Brushes的所有控件现在都将使用您重写的Brushes,这可能不是您想要的。
SystemColors.InactiveSelectionHighlightBrushKey
和SystemColors.InactiveSelectionHighlightTextBrushKey
仅适用于.NET 4.5或更高版本。 - bitbonk