[英]Content alignment in label WPF
我在标签中对齐文本时遇到一个小问题
这是我的xaml代码
<GroupBox Header="Normal" Width="450" Height="150" Name="grpNormal">
<Canvas Name="cvsNormal" Width="440" Height="140">
<Label Name="lblStartRegNormal" Width="223" Content="Enter the starting reg number: " FontSize="16" Canvas.Left="2" Canvas.Top="15" HorizontalContentAlignment="Right" />
<TextBox Name="txtStartRegNormal" Height="40" Width="200" Canvas.Right="10" Canvas.Top="15"/>
<Label Name="lblEndRegNormal" Width="223" Content="Enter the ending reg number: " FontSize="16" Canvas.Left="5" Canvas.Top="65" HorizontalContentAlignment="Right"/>
<TextBox Name="txtEndRegNormal" Height="40" Width="200" Canvas.Right="10" Canvas.Top="65"/>
</Canvas>
</GroupBox>
这是输出
但是当我更改标签内容时,右侧的冒号不对齐
我在这做错了什么?
<GroupBox Header="Normal" Width="450" Height="150" Name="grpNormal">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Name="lblStartRegNormal" Width="223" Content="Enter the starting reg number: " FontSize="16" HorizontalContentAlignment="Right" />
<TextBox Name="txtStartRegNormal" Grid.Column="1" Height="40" Width="200"/>
<Label Grid.Row="1" Name="lblEndRegNormal" Width="223" Content="Enter the ending reg number: " FontSize="16" HorizontalContentAlignment="Right"/>
<TextBox Name="txtEndRegNormal" Height="40" Grid.Row="1" Grid.Column="1" Width="200" />
</Grid>
</GroupBox>
它看起来像这样:
如果您使用Snoop WPF检查正在运行的应用程序,您会发现标签可视树包含一个边框元素宽度,填充为5,5,5,5。
如果你使用SnoopWPF删除填充,一切都很好。 这表明虽然标签宽度为223,但文本内容的宽度较小,并且在较长文本上延伸到此填充。 尝试使标签略宽或仅使用TextBlock。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.