WPF: style setting for immediate children only

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

I tried to set the following style in the tab control, but this also affects all children:

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

Using the code above, I get the following error: "TabItem" ControlTemplate TargetType does not match a "TabControl" template, because TabItem and TabControl have the same DependencyProperty "Template" and the code tries to set TabItemTemplate as a TabControl - Template.

Can someone help me?

+4
source share
1 answer

Use the ItemContainerStyle property to apply style to elements of an element control:

 <Style x:Key="tabControlStyle" TargetType="{x:Type TabControl}"> <Setter Property="ItemContainerStyle" Value="{x:StaticResource tabItemStyle}" /> </Style> 
+3
source

Source: https://habr.com/ru/post/1311345/


All Articles