Kokombads
Kokombads

Reputation: 460

Templated TabItem header does not show Header content

I got a TabControl with two TabItems, I created a template for it.

<TabControl x:Name="MainInfoTabControl" Grid.Row="3" Grid.RowSpan="7" Grid.Column="0" Grid.ColumnSpan="2" 
                    Background="{x:Null}"
                    BorderBrush="{x:Null}"
                    >
            <TabControl.Resources>

                <Style x:Key="TabHeaderStyle" TargetType="{x:Type TabItem}">
                    <Setter Property="Background" Value="{x:Null}" />
                    <Setter Property="FontWeight" Value="DemiBold" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type TabItem}">
                                <Border x:Name="HeaderBorder" BorderBrush="White" BorderThickness="2" CornerRadius="10,10,0,0" >

                                    <TextBlock Text="" VerticalAlignment="Center" Margin="5"></TextBlock>


                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </TabControl.Resources>


            <TabItem Header="Main Details" 
                     Margin="0.5, 0.5, 0, 0.5"
                     FontSize="15"
                     MinHeight="40" Width="200"                     
                     Style="{StaticResource TabHeaderStyle}"
                     >         

            </TabItem>


            <TabItem Header="Pets Owned" 
                     Margin="0.5, 0.5, 0, 0.5"
                     FontSize="15"
                     MinHeight="40" Width="200"                     
                     Style="{StaticResource TabHeaderStyle}"
                     >

            </TabItem>


</TabControl>

The problem is the tabItem's Header doesn't show up. In my template there is a TextBlock but i couldn't customize the TextBlock.Text dynamically (atleast bind or somewhat change the Text property during run time)

TabItem1 should be "Owner Details" while TabItem2 should be "Pets Owned"

Upvotes: 0

Views: 147

Answers (1)

Maximus
Maximus

Reputation: 3448

You override default tabitem template you need to get somehow to parent's value.

 <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Header}" 
            VerticalAlignment="Center"
            Margin="5">
 </TextBlock>

or

<TextBlock Text="{TemplateBinding Property=Header}"
          VerticalAlignment="Center" 
          Margin="5">
</TextBlock>

Upvotes: 1

Related Questions