Pergunta

I'm trying something with TabControl and am flummoxed by this

<TabControl Name="MainControl">
    <TabItem Header="MyTab1">
    <TextBlock Text="{Binding  Path=SelectedItem.Header, RelativeSource={RelativeSource FindAncestor, AncestorType=TabControl}}"/>
    </TabItem>
    <TabItem Header="Modules" ContentTemplate="{StaticResource tabItemControl}"/>
</TabControl>

this works as expected.

However this :

<TabControl Name="MainControl">
    <TabItem Header="MyTab1">
    <TextBlock Text="{Binding  Path=Header, RelativeSource={RelativeSource FindAncestor, AncestorType=TabItem}}"/>
    </TabItem>
    <TabItem Header="Modules" ContentTemplate="{StaticResource tabItemControl}"/>
</TabControl>

does not.

Any idea why?

Is the selectedItem not a TabItem? Is there something different in the hierarchy?

Foi útil?

Solução

As shown in the post RelativeSource in DataTemplate works with TabControl but not with TabItem the TabItem and SelectedContent are hosted in different panels hence SelectedItem.Header is not working as it's not actually a tabItem

Posting the snoop image from the earlier post below enter image description here

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top