WPF: How to set background of TabItem?

怎甘沉沦 提交于 2019-12-05 01:17:35
Oppositional

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.

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>

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!