WPF: Set style on immediate children only

Posted by ollifant on Stack Overflow See other posts from Stack Overflow or by ollifant
Published on 2010-05-30T12:43:02Z Indexed on 2010/05/30 12:52 UTC
Read the original article Hit count: 157

Filed under:

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?

© Stack Overflow or respective owner

Related posts about wpf