tags:

views:

16

answers:

1

In my application I have a tab control which has several tab items. The problem is that I want to apply a style to these tab items, but to no other (nested) tab items.

I have tried setting the following style on the tab control, but this also effects all children:

<Style x:Key="tabControlStyle" TargetType="{x:Type TabControl}">
     <Setter Property="TabItem.Template" Value="{StaticResource tabItemTemplate}" /> 
</Style>

By using the code above I get the following error: 'TabItem' ControlTemplate TargetType does not match templated type 'TabControl', as TabItem and TabControl have the same DependencyProperty "Template", and the code tries to set the TabItemTemplate as TabControl- Template.

Can anybody help me?

+3  A: 

Use the ItemContainerStyle property to apply a style to the items of an items control:

<Style x:Key="tabControlStyle" TargetType="{x:Type TabControl}">
     <Setter Property="ItemContainerStyle" Value="{x:StaticResource tabItemStyle}" /> 
</Style>
Julien Lebosquain
That might work for this case, but I have similar usages where the parent is not an ItemControl. What can I do in these cases?
ollifant
When it's not an ItemsControl that means the children have been created by you, not by the framework so you have full control of the template and style to apply.
Julien Lebosquain
Yes, but what if I don't want to set the same style on 20 controls?
ollifant