[英]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.