【发布时间】:2021-03-30 21:09:15
【问题描述】:
我有一个TabControl 和一些TabItems。
TabItems 的标头由 UserControl 和 label 和 button 组成。
为此,我关注了tutorial。
label 的水平对齐不起作用,因为宽度设置为自动。
这会导致文本居中,buttons 并非一直位于它们应位于的右侧。
但我需要宽度灵活,以免长文本被截断。
这是宽度设置为自动,这是固定宽度。
我希望它看起来像具有固定宽度但根据标签长度具有灵活宽度的图片。
编辑:我不使用 cmets 中提出的建议中的主题。
这是我的 XAML 代码:
<UserControl
x:Class="CSM.UserControls.CloseableHeaderUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignWidth="81" Margin="0" Height="20.5" >
<Grid Margin="0,4,0,0">
<Button Content="X" Name="bClose" FontFamily="Courier" FontWeight="Bold" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" FontStretch="Normal" FontSize="14" ToolTip="Close" Height="20" Width="20" HorizontalAlignment="Right" Margin="0,-4,0,0"/>
<Label Content="TabItem" Name="lTabTitle" FontFamily="Courier" FontSize="12" HorizontalAlignment="Left" HorizontalContentAlignment="Left" Width="auto" Height="24" VerticalAlignment="Top" Margin="0,-4" />
</Grid>
</UserControl>
【问题讨论】:
-
@Ash 很遗憾这没有帮助
标签: wpf width tabcontrol text-alignment tabitem