简体   繁体   English

默认 TabItem 背景颜色

[英]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.如果选项卡中未设置某些内容,我想设置 TabItem Header (TabItem.Background) 的背景颜色。 To accomplish this, I have a Brush property in my ViewModel that is bound to the Background property of the TabItem.为此,我在 ViewModel 中有一个 Brush 属性,该属性绑定到 TabItem 的 Background 属性。 However, I'm not sure how to get/create the default TabItem background brush.但是,我不确定如何获取/创建默认的 TabItem 背景画笔。

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.我希望DefaultTabItemBrush画笔与其他 TabItems 相匹配,因此如果主题发生更改,所有 TabItems 看起来仍然相同。

Is the default brush available in SystemColors? SystemColors 中是否提供默认画笔?

Using C# / .NET 3.5使用 C# / .NET 3.5

I ended up using the solution from In WPF, how do I get the current theme's button background?我最终使用了In WPF 中的解决方案,如何获取当前主题的按钮背景?

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当 IsContentSet == true 时,它将使用默认画笔,当为 false 时,在这种情况下使用其他画笔 LightSKyBlue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM