WPF:如何设置 TabItem 的背景? [英] WPF: How to set background of TabItem?

查看:29
本文介绍了WPF:如何设置 TabItem 的背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to set the background of TabItem? I tried the following code:

<TabControl>
    <TabItem Header="Test" Background="Blue" Foreground="Red" />
</TabControl>

Foreground 有效,但 Background 无效.

有什么想法吗?谢谢

推荐答案

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

What is happening is that in the case of a single tab, it is always selected, and so you are only seeing the selection style of the tab item.

以下面的TabControl为例:

For example, take a look at the following 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 不会显示其蓝色背景.如果您真的希望无论是否选中,Background 都保持不变,则需要覆盖 TabItem 的控件模板.

Tab A will not display its Blue background until you select a different tab. If you truly want the Background to remain the same regardless of whether it is selected or not, you will need to override the control template of the TabItem.

看问题TabItem 背景颜色变化选择 tabitem 或将鼠标悬停在 上以获取如何执行此操作的示例.

See the question TabItem Background color changes when tabitem selected or hover over for an example of how to do this.

这篇关于WPF:如何设置 TabItem 的背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆