Text alignment is not working #19287
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Compare these two samples of a canvas and a stack panel (I have added a border of clarity) <Border Width="300" Height="328" BorderBrush="Black" BorderThickness="2">
<Canvas >
<TextBlock FontSize="20" TextAlignment="Center">
Completed 1 hour 21 minutes
</TextBlock>
</Canvas>
</Border> <Border Width="300" Height="328" BorderBrush="Black" BorderThickness="2">
<StackPanel>
<TextBlock FontSize="20" TextAlignment="Center">
Completed 1 hour 21 minutes
</TextBlock>
</StackPanel>
</Border> With a stack panel the text box stretches to fill the entire width so there is extra space inside the text box to centre the text in. A canvas basically requires you to choose the exact position everything appears in. So you would have to calculate the offset needed for the text box. Or does the whole control need to be a canvas? Could the part that needs to be drawn on the canvas be embedded in a panel type which will allow you to easily centre the text box? |
Beta Was this translation helpful? Give feedback.
TextAlignment
aligns the text within the amount of space that the text box is taking up. The alignment is relative to the size of the text box. As you are using a canvas the text box is only sized to the amount of space required to show the text.Compare these two samples of a canvas and a stack panel (I have added a border of clarity)