Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically align tops of blocks of text in WPF

I'm trying to visually align the top of the content of 2 (or more) blocks of Text. The content and the Font (Size, Family, Weight) of each block can be modified by user.

I tried to play with the GetCellAscent, GetCellDescent and GetLineSpacing functions but the results depends only on the font and not the real content. And anyway I can't find how is distributed the difference between LineSpacing and Ascent+ Descent at the top and bottom of the block.

For example I want to produce this kind of output:

enter image description here

Any help?

like image 687
user2223898 Avatar asked Nov 13 '22 07:11

user2223898


1 Answers

Try This.....

   <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>
like image 80
YOusaFZai Avatar answered Nov 14 '22 22:11

YOusaFZai