开发者

How to set selected value path to tab header text in a tab control in WPF

开发者 https://www.devze.com 2023-01-14 04:23 出处:网络
I am a little unclear on how I would set 开发者_如何学JAVAthe SelectedValuePath of a TabControl to the text of the selected TabItems header. I feel like this should be fairly simple, and probably invo

I am a little unclear on how I would set 开发者_如何学JAVAthe 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.


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

精彩评论

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