WPF:如何设置 TabItem 的背景?

标签 wpf wpf-controls tabitem

如何设置TabItem的背景?我尝试了以下代码:

<TabControl>
    <TabItem Header="Test" Background="Blue" Foreground="Red" />
</TabControl>
Foreground有效,但 Background不起作用。

enter image description here

有任何想法吗?谢谢

最佳答案

发生的情况是,在单个选项卡的情况下,它始终处于选中状态,因此您只能看到选项卡项的选择样式。

例如,看看下面的 TabControl:

<TabControl>
    <TabItem Header="Tab A" Background="Blue" Foreground="Red">
        <Grid />
    </TabItem>

    <TabItem Header="Tab B" Background="Green" Foreground="Navy" >
        <Grid />
    </TabItem>

    <TabItem Header="Tab C" Background="LightBlue">
        <Grid />
    </TabItem>

</TabControl>

在您选择不同的选项卡之前,选项卡 A 不会显示其蓝色背景。如果您真的希望背景无论是否被选中都保持不变,则需要覆盖 TabItem 的控件模板。

看问题TabItem Background color changes when tabitem selected or hover over有关如何执行此操作的示例。

关于WPF:如何设置 TabItem 的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6273847/

相关文章:

c# - 在 XML 中保存 ImageSource (BitmapSource)

wpf - 是否有类似于 Prism 中使用的桌面应用程序事件聚合器之类的东西?

wpf - 如何禁用 AutoSuggestBox 上的拼写检查器

c# - WPF Combobox isEditable 绑定(bind)条目到列表

wpf - 如何在 WPF 的 ListView 中有图像和按钮列

wpf - TabControl.Orientation?

c# - 控制模板资源中 Storyboard 的 Hooking Completed 事件的问题

c# - 有没有更简单的方法来使用未知类型进行类型转换?

SwiftUI TabView 覆盖内容 View

c# - WPF:TabControl 和动态 TabItems