开发者

WPF: Get Tabtitle from Content (in template)

开发者 https://www.devze.com 2023-01-21 22:46 出处:网络
I\'m trying to display the Title of an Tabitem in his contentpresenter. Is there a possibility to get this name?

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!


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}"/>


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


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

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

精彩评论

暂无评论...
验证码 换一张
取 消