我已经在 tabcontrol 中设置了 tabitem 的样式
<Style x:Key="TabHeaderStyle" TargetType="{x:Type TabItem}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate >
<Grid HorizontalAlignment="Stretch" Height="22">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
</Grid.RowDefinitions>
<Rectangle Fill="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem} }, Path=Content.DataContext.HeaderColor}" Grid.ColumnSpan="2"></Rectangle>
<TextBlock Grid.Row="1" Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem} }, Path=Content.DataContext.HeaderInfo}"
VerticalAlignment="Bottom" Margin="4,0,8,0"/>
<Button Grid.Row="1" Grid.Column="1" Content="x" ToolTipService.ToolTip="Close this view." BorderBrush="{x:Null}" Background="{x:Null}" Foreground="#FF224A71" VerticalAlignment="Center" Padding="3,0">
<Button.OpacityMask>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#4BFFFFFF" Offset="1"/>
</LinearGradientBrush>
</Button.OpacityMask>
<ei:Interaction.Triggers>
<ei:EventTrigger EventName="Click">
<Controls:CloseTabbedViewAction />
</ei:EventTrigger>
</ei:Interaction.Triggers>
</Button>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
当我像这样打开几个标签时,tabitem 看起来不错
这个看起来不错,“x”,右对齐的近视图。我的问题是,当我打开更多选项卡时,标准选项卡控件功能是在选项卡空间很小时添加一行。发生这种情况时,tabitems 会调整大小,但它们似乎没有通知子控件,因为选项卡看起来像这样
请注意,“x”没有像以前那样右对齐。我试图将数据模板基于不同样式的网格和堆栈面板,但无济于事。任何人都知道即使我有多行选项卡,我将如何使“x”按钮右对齐。