【发布时间】:2024-01-13 15:10:01
【问题描述】:
我正在尝试让我的 WPF TabItems 使其标题文本居中。但无论我在 ContentPresenter 及其包含的 Border 上设置了 HorizontalAlignment 和 HorizontalAlignment(居中或拉伸)的哪种组合,文本总是显示为左对齐,而不是居中。我也没有在 TabItems 上看到可以用来直接在选项卡项本身上设置它的属性(事实证明,TabItem 上的 HorizontalAlignment 做了完全不同的事情)。
我现在的代码是这样的:
<Grid TextElement.Foreground="White" TextElement.FontSize="17" TextElement.FontFamily="Times New Roman" HorizontalAlignment="Center" >
<Border Name="TabBorder" BorderThickness="8 8 8 0" CornerRadius="12 12 0 0"
Background="{StaticResource bandBrush}" HorizontalAlignment="Center" >
<ContentPresenter HorizontalAlignment="Stretch" ContentSource="Header" Height="24" Width="100" />
</Border>
</Grid>
【问题讨论】:
标签: c# wpf xaml header tabitem