How i implement HeaderStyle for TabItem

Dec 20, 2012 at 11:45 PM

Hello,

i have read in the documentation that tab control work diffrent and i have to tab's header with te parameter HeaderStyle.

My TabControl Binds on a Collection of a Class with two Parameters: "View" and "DisplayName".

MyCode:

<TabControl ItemsSource="{Binding ActiveModulesListView}" ContentTemplate="{StaticResource ContentTemplate}" />

and Resources:

<DataTemplate x:Key="ContentTemplate">
    <ContentPresenter Content="{Binding Path=View}" />
</DataTemplate>

I have not solved to bind tab's header to DisplayName (String).

Can someone help me? 

Coordinator
Dec 21, 2012 at 8:25 AM
Edited Dec 21, 2012 at 8:28 AM

Hello! Try this

<TabControl ItemsSource="{Binding ActiveModulesListView}" ContentTemplate="{StaticResource ContentTemplate}">
    <TabControl.Resources>
        <Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
            <Setter Property="Header" Value="{Binding Path=DisplayName}"/>
        </Style>
    </TabControls.Resources>
</TabControl>

Marked as answer by afsherman on 10/7/2013 at 6:34 PM
Dec 22, 2012 at 11:05 AM

It works! Thank you very much.

Jun 28, 2013 at 8:52 AM
Edited Jun 28, 2013 at 8:53 AM
The DataTemplate way works in default TabItem style and some other simply customized styles.

Could you please kindly explain why it doesn't work in your style? It would be great if it works. Thanks!
Developer
Jan 16, 2014 at 10:12 AM
Could you please kindly explain why it doesn't work in your style?
I guess because he is trying to bind the TabItem to custom class (view) using some MVVM framework like Caliburn.Micro or similar.