Reputation: 2214
I am learning to use styles in wpf and I am creating a style for a Tab Control. I was wandering if someone can please tell how I can stop a style propagating down, for example I have a Tab control that where one of the tabitems holds another tabcontrol, of closable tabitems, (yes Nested TabControl O.o).
So in my first UserControl it holds the "Master" TabControl this UserControl also has a UserControl.Rescource that has a style for this TabControl. This style propogates down to the nested tabcontrol, how can I stop this from happening?
The other tab control is kept in a seperate usercontrol class. Looks Something like this:
<UserControl.Resources>
<Style TargetType="{x:Type TabControl}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Template">
...
<!-- The Style -->
...
</UserControl.Resources>
<TabControl SelectedIndex="{Binding Path=TabIndexFocus}">
<TabItem Header="Tab1" IsEnabled="{Binding Path=IsEnabled_WorkSpace}" >
<View:NestedTabControl/>
</TabItem>
<TabItem Header="Tab2">
<View:SomeOtherView />
</TabItem>
.....
</TabControl>
Thanks All :D
Upvotes: 1
Views: 780
Reputation: 23280
Make a copy of the entire default Style Template, then I would recommend putting it in a separate resource dictionary but either way you will give the style template a unique x:Key name so like;
<Style x:Key="NonDefaultTabControlStyle" Target="{x:Type TabControl}">
Then in your tab control itself call your specific Style template like;
<TabControl Style="{StaticResource NonDefaultTabControlStyle}" ....>
When you specify the uniquely named Style template it will use it, when you don't it will use the default. Hope this helps and best of luck!
Upvotes: 1