freakinpenguin
freakinpenguin

Reputation: 867

WPF: Get Tabtitle from Content (in template)

I'm trying to display the Title of an Tabitem in his contentpresenter. Is there a possibility to get this name?

For example in the Tabcontrol Template something like

<Label>
    <ContentPresenter ContentSource="SelectedContentHeader" Grid.Row="1" />
</Label>

to display the name of the current tab in label.

Thanks in advance!

Upvotes: 0

Views: 164

Answers (3)

John Bowen
John Bowen

Reputation: 24453

<Label Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TabItem}}, Path=Header}"/>

Upvotes: 0

freakinpenguin
freakinpenguin

Reputation: 867

Thanks to arx for the right direction ;) EDIT: And also thanks to John

   <Label Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.Header}" />

Upvotes: 0

arx
arx

Reputation: 16896

I'm not quite sure what you are trying to do, (e.g. is the label part of a control template or separate?), but this displays tabControl1's current TabItem's name in a label:

<Label Content="{Binding ElementName=tabControl1,Path=SelectedItem.Header}"/>

Upvotes: 1

Related Questions