我正在尝试在视觉上align
2个(或更多)Text
块的内容的顶部。
用户可以修改每个块的内容和Font
(Size
,Family
,Weight
)。
我尝试使用GetCellAscent
,GetCellDescent
和GetLineSpacing
函数,但结果仅取决于字体,而不取决于实际内容。无论如何,我无法找到该块顶部和底部的LineSpacing
和Ascent+ Descent
之间的差异是如何分布的。
例如,我想产生这种输出:
有什么帮助吗?
最佳答案
试试这个.....
<Grid Width="171" Height="100" Background="Black" Margin="257,78,75,133">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Name="aaa" Text="12" FontSize="40" HorizontalAlignment="Center" VerticalAlignment="Stretch" Grid.Row="1" FontWeight="Bold" Foreground="White" />
<TextBlock Text="$" HorizontalAlignment="Left" FontSize="20" Grid.Column="1" FontFamily="Euphemia" FontWeight="Bold" Foreground="White" Margin="8,0,72,0" />
<TextBlock Text="00 le Kg" FontSize="15" Grid.Column="1" Grid.Row="3" HorizontalAlignment="Left" Grid.IsSharedSizeScope="True" FontFamily="Euphemia" FontWeight="Bold" Foreground="White"/>
</Grid>