带TabItems的示例TabControl"你好"和" bye" 我需要看到标签标题为"你好 - 22"和" bye - 33"在目前的情况下,但标签有"你好 - "和" bye - "头。
<TabControl>
<TabControl.Resources>
<Style TargetType="TabItem">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type TabItem}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding}"/>
<TextBlock Text=" - "/>
<TextBlock Text="{TemplateBinding Tag}"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
<TabItem Header="hello" Tag="22"></TabItem>
<TabItem Header="bye" Tag="33"></TabItem>
</TabControl>
为了获得有效的WPF,我需要改变什么?
答案 0 :(得分:0)
必须是:
<TextBlock Text="{Binding}"/>
<TextBlock Text=" - "/>
<TextBlock Text="{Binding Tag, RelativeSource={RelativeSource AncestorType=TabItem}}"/>