wpf TreeView 为所选项目显示蓝色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17814308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TreeView shows blue for selected item
提问by HXD
I have a treeview structure. When I try to click on the nodes there is a blue color that shows the node selected. How can I remove that. I don't want a selection color to be displayed on the tree.
我有一个树视图结构。当我尝试单击节点时,会出现蓝色显示所选节点。我怎样才能删除它。我不想在树上显示选择颜色。
回答by Viv
ItemContainerStylemethod does not work for me say on Windows-8. There are 4 brushes that generally correspond to this and are used by the default Template for TreeViewItem
ItemContainerStyle方法对我来说在 Windows-8 上不起作用。有 4 个画笔通常对应于此,并由默认模板用于TreeViewItem
keys:
键:
HighlightBrushKey- Background with focus.
HighlightBrushKey- 重点背景。
HighlightTextBrushKey- Foreground with focus.
HighlightTextBrushKey- 有焦点的前景。
InactiveSelectionHighlightBrushKey- Background without focus.
InactiveSelectionHighlightBrushKey- 没有焦点的背景。
InactiveSelectionHighlightTextBrushKey- Foreground without focus.
InactiveSelectionHighlightTextBrushKey- 没有焦点的前景。
Just override them as you see fit, for your requirement something like this would do fine:
只需按照您认为合适的方式覆盖它们,对于您的要求,这样的事情就可以了:
<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>
Do pay attention to only overriding them within the scope you require. For example if you put all this into App.xaml you're going to see some weird side-effects as all control's using these Brushes would now end up using your overridden ones which may not be what you're after.
请注意仅在您需要的范围内覆盖它们。例如,如果您将所有这些都放入 App.xaml 中,您将看到一些奇怪的副作用,因为使用这些笔刷的所有控件现在最终会使用您覆盖的那些,而这可能不是您所追求的。

