Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the default style for tabitem in a tabcontrol's style

Tags:

wpf

tabcontrol

I'm creating a specific style for some TabControl in my application.

<TabControl Style="{StaticResource MyTabControl}">
</TabControl>

I want to also style TabItem in the case of this specific TabControl's Style.

For now, I must write :

<TabControl Style="{StaticResource MyTabControl}">
    <TabItem Style="{StaticResource MyTabItem}" Header="First" />
    <TabItem Style="{StaticResource MyTabItem}" Header="Second" />
</TabControl>

Instead of having to specify the "MyTabItem" style on each TabItem, is there any way to set the default TabItem style only in the scope of a specific TabControl Style ?

I didn't found a way to specify, in the style of my TabControl, which style should be applied on all children TabItems.

like image 594
tbolon Avatar asked Jan 14 '11 17:01

tbolon


2 Answers

<TabControl ItemContainerStyle="{StaticResource MyTabItem}"/>
like image 88
Kent Boogaart Avatar answered Nov 16 '22 09:11

Kent Boogaart


put style for target type TabItem as a implicit style under your MyTabItem style resource

<Style TargetType="TabControl" x:Key="TabControlStyle">
            <Style.Resources>
                <Style TargetType="TabItem">

                </Style>
like image 2
Ivan Avatar answered Nov 16 '22 08:11

Ivan