Search code examples
wpfbindingtabcontroltabitem

How to bind the name of the active TabItem to a Label in WPF?


actual the Labels shows the namespace of the control and not the name (header) of the active tabitem.

..
<Label Content="{x:Type TabControl}" />
</Grid>

<TabControl>

    <TabItem Header="Header1" />
    <TabItem Header="Header2" />
    ..

Solution

  • You obviously have no clue about what you are doing, read this: Data Binding Overview
    The x:Type markup extension has nothing to do with binding, it just returns the type of a given class.


    One way to bind to the selected item:

    <Label Content="{Binding ElementName=tc, Path=SelectedItem.Header}"/>
    <TabControl Name="tc" ...>
         <!-- Items -->
    </TabControl>
    

    (Note: The SelectedItem normally (- when using ItemsSource -) does not represent the selected control but the data behind the selected item)