-2

Consider the following xaml:

<Window x:Class="DemoApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Title="DemoApp.MainWindow" Height="450" Width="800">
    <StackPanel Orientation="Horizontal">
        <Label BorderThickness="1" BorderBrush="Black" Width="100" Height="100" FontSize="120" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0">A</Label>
    </StackPanel>
</Window>

As shown in the image below, there is plenty of space within the label to accomodate the letter, yet it appears that the letter does not center as per the VerticalContentAlignment. What is the cause of this?

Output of above code.

Harry Will
  • 131
  • 7
  • Yes, thank you - it appears an issue with the GlyphOffset. How did you find that, I searched high and low but could not find anything remotely like that? – Harry Will Oct 26 '20 at 15:45
  • I had to deal with a similar issues related to fonts in the past :-) . – thatguy Oct 26 '20 at 15:56

1 Answers1

0

I think VerticalContentAlignment has no problem. Problem is that your Label is smaller than Font size.

<Label BorderThickness="1" BorderBrush="Black" Width="100" FontSize="120" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0">A</Label>

Try this code. I removed code "Height=100" and height is auto.

Jack Lee
  • 363
  • 5
  • 18
  • As expressed within the question, the label is plenty large enough for the font size, so that is not a solution. Thank you anyway. – Harry Will Oct 26 '20 at 15:43