I have a tab control with two different potential item templates:
<TabControl ItemTemplateSelector="{StaticResource tabTemplateSelector}"/>
Now, I also have styles for it:
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
...
The thing is, I want the tab item style template to be different depending on the value of ItemTemplateSelector. How can I do this? Basically, I don’t want that entire style rule to be applied to every tab item, just the ones with a specific tab item template.
Update: to make it clearer, the style has TargetType set to TabItem. I want to apply that style only to those tab items that have a specific item template.
The
ContentPresenterin theControlTemplatewill display what’s in theItemTemplate. So you won’t be able to switch theTemplatefrom inside theControlTemplate.Instead, you could use a
DataTriggerto set theTemplate. TheDataTriggerwill check if theItemTemplatethat will be generated should have the otherTemplateor not.You will probably need a converter for this but here is an easy example. Say that your
ItemTemplateSelectorreturns the otherDataTemplateifNameis equal to “Tab 2”. Then yourStylewith theDataTriggerwould look like this