Search code examples
c#.netwpf.net-3.5systemcolors

Default TabItem Background Color


I want to set the background color of a TabItem Header (TabItem.Background) if certain content is not set in the tab. To accomplish this, I have a Brush property in my ViewModel that is bound to the Background property of the TabItem. However, I'm not sure how to get/create the default TabItem background brush.

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

I would like the DefaultTabItemBrush brush to match the other TabItems so if the Theme changes all the TabItems will still look the same.

Is the default brush available in SystemColors?

Using C# / .NET 3.5


Solution

  • I ended up using the solution from In WPF, how do I get the current theme's button background?

    Then in my code looks something like:

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

    When IsContentSet == true it will use the default brush and when false some other brush in this case LightSKyBlue