开发者

WPF: How to set background of TabItem?

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

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

Foreground works, but Background does not wo开发者_StackOverflow社区rk.

WPF: How to set background of TabItem?

Any ideas? Thanks


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜