Align vertices of text blocks vertically in WPF

I am trying to visually display the aligntop of the contents of two (or more) blocks Text. Content and Font( Size, Family, Weight) may be changed by the user of each block.

I tried to play with functions GetCellAscent, GetCellDescentand GetLineSpacing, but the results depend only on the font, and not on the actual content. And in general, I can’t find how the difference is distributed between LineSpacingboth Ascent+ Descentthe top and bottom of the block.

For example, I want to create the following output:

enter image description here

Any help?

+5
source share
1 answer

Try it.....

   <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>
+1
source

All Articles