2011-07-20 215 views
2

我想設置一個TabItem標題(TabItem.Background)的背景顏色,如果某些內容沒有在標籤中設置。爲了做到這一點,我在ViewModel中有一個Brush屬性,綁定到TabItem的Background屬性。但是,我不確定如何獲取/創建默認的TabItem背景畫筆。默認的TabItem背景顏色

public Brush TabItemBrush 
{ 
    get 
    { 
     return IsContentSet ? DefaultTabItemBrush : Brushes.LightSkyBlue; 
    } 
} 
<TabItem Header="Some Header" Background="{Binding TabItemBrush, Mode=OneWay}"> 

我想DefaultTabItemBrush刷,以配合其他的TabItems所以如果主題更改所有的TabItems仍然看起來是一樣的。

是SystemColors中的默認畫筆嗎?

使用C#/。NET 3.5

+0

I在這篇文章中找到了一個可接受的解決方案:http://stackoverflow.com/questions/4198500/in-wpf-how-do-i-get-the-current-themes-button-background/4198971#comment-8027648 –

+0

你有沒有有沒有從SystemColors中找到默認的畫筆? – tofutim

回答

1

我結束了使用從In WPF, how do I get the current theme's button background?

然後在我的代碼的解決方案看起來是這樣的:

public Brush TabItemBrush 
{ 
    get 
    { 
     return IsContentSet ? (Brush)UIUtilities.GetValueFromStyle(typeof(TabItem), Control.BackgroundProperty) : Brushes.LightSkyBlue; 
    } 
} 
<TabItem Header="Some Header" Background="{Binding TabItemBrush, Mode=OneWay}"> 

當IsContentSet == true時將使用默認的畫筆,當在這種情況下假的其他畫筆LightSKyBlue

相關問題