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

江枫思渺然 提交于 2019-12-03 17:47:40

问题


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.


回答1:


<TabControl ItemContainerStyle="{StaticResource MyTabItem}"/>



回答2:


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>


来源:https://stackoverflow.com/questions/4693759/how-to-set-the-default-style-for-tabitem-in-a-tabcontrols-style

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