我对如何将TabControl的SelectedValuePath设置为所选TabItems标题的文本有点不清楚。我觉得这应该是相当简单的,可能涉及content.something但我总是对Content属性有点困惑。
答案 0 :(得分:0)
ItemTemplate - 标签标题的模板。只需添加具有与属性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'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"/>