Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

wpf - TreeView shows blue for selected item

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

ItemContainerStyle method 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

keys:

HighlightBrushKey - Background with focus.

HighlightTextBrushKey - Foreground with focus.

InactiveSelectionHighlightBrushKey - Background without focus.

InactiveSelectionHighlightTextBrushKey - Foreground without focus.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...