views:

30

answers:

1

The title really says it all here. I am a little unclear on how I would set the SelectedValuePath of a TabControl to the text of the selected TabItems header. I feel like this should be fairly simple, and probably involves content.something but I have always been a bit confused about the Content property.

Thanks

A: 

ItemTemplate — template for tab headers. Just add textblock with the same binding as in property SelectedValuePath.

<UserControl.Resources>
    <XmlDataProvider x:Key="Employees" XPath="/Employees/*">
        <x:XData>
            <Employees xmlns="">
                <Employee Name="Terry Adams" Type="FTE" EmployeeNumber="1" />
                <Employee Name="Claire O&apos;Donnell" Type="FTE" EmployeeNumber="12345" />
                <Employee Name="Palle Peterson" Type="FTE" EmployeeNumber="5678" />
                <Employee Name="Amy E. Alberts" Type="CSG" EmployeeNumber="99222" />
                <Employee Name="Stefan Hesse" Type="Vendor" EmployeeNumber="-" />
            </Employees>
        </x:XData>
    </XmlDataProvider>

    <DataTemplate x:Key="HeaderDataTemplate">
        <TextBlock Text="{Binding XPath=@EmployeeNumber}" />
    </DataTemplate>
    <DataTemplate x:Key="ContentDataTemplate">
        <TextBlock Text="{Binding XPath=@Name}" />
    </DataTemplate>
</UserControl.Resources>

<TabControl ItemsSource="{Binding Source={StaticResource Employees}}"
         ItemTemplate="{StaticResource HeaderDataTemplate}"
         ContentTemplate="{StaticResource ContentDataTemplate}"
         SelectedValue="12345"
         SelectedValuePath="@EmployeeNumber"/>
vorrtex