2013-07-23 62 views
17

我有一個treeview結構。當我嘗試點擊節點時,會出現藍色,顯示所選節點。我如何刪除它。 我不希望選擇顏色顯示在樹上。TreeView顯示藍色的選定項目

+0

此問題已被提問並回答了數百萬次。 –

+0

可能的重複[如何突出顯示樹形視圖選擇的項目與某種顏色?](http://stackoverflow.com/questions/876759/how-do-i-highlight-a-treeview-selected-item-with-some -color) –

回答

43

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中,您將看到一些奇怪的副作用,因爲所有使用這些畫筆的控件現在都將使用您的重寫內容,而這些內容可能並非您所追求的內容。

+1

謝謝,這正是我一直在尋找的! – HXD

+2

請注意,'SystemColors.InactiveSelectionHighlightBrushKey'和'SystemColors.InactiveSelectionHighlightTextBrushKey'僅適用於.NET 4.5或更高版本。 – bitbonk