I'm creating a specific style for some TabControl in my application.
我正在为我的应用程序中的一些TabControl创建一个特定的样式。
<TabControl Style="{StaticResource MyTabControl}">
</TabControl>
I want to also style TabItem in the case of this specific TabControl's Style.
我还想为这个特定的TabControl样式设置样式。
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 ?
不需要在每个表项上指定“MyTabItem”样式,是否有办法只在特定的表控件样式的范围内设置默认的TabItem样式?
I didn't found a way to specify, in the style of my TabControl, which style should be applied on all children TabItems.
我没有找到一种方法来指定选项卡控件的样式,即应该将哪种样式应用于所有子选项卡项。
2 个解决方案
#1
19
<TabControl ItemContainerStyle="{StaticResource MyTabItem}"/>
#2
2
put style for target type TabItem as a implicit style under your MyTabItem style resource
将目标类型TabItem的样式作为MyTabItem样式资源的隐式样式。
<Style TargetType="TabControl" x:Key="TabControlStyle">
<Style.Resources>
<Style TargetType="TabItem">
</Style>
#1
19
<TabControl ItemContainerStyle="{StaticResource MyTabItem}"/>
#2
2
put style for target type TabItem as a implicit style under your MyTabItem style resource
将目标类型TabItem的样式作为MyTabItem样式资源的隐式样式。
<Style TargetType="TabControl" x:Key="TabControlStyle">
<Style.Resources>
<Style TargetType="TabItem">
</Style>