Admiral Land Admiral Land - 26 days ago 14
C# Question

How to centered Content from Label

I have a

Grid
:

<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="10*"></RowDefinition>
<RowDefinition Height="80*"></RowDefinition>
</Grid.RowDefinitions>

<Label Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Content="Text to center!" BorderBrush="Blue" BorderThickness="5">
</Label>
</Grid>


But at that variant I have a
Label
from all the
Grid
rows, but its
Content
goes to left side of the row.
How to make the
Content
centered ?
If I type
HorizontalAlignment="Center"
Label
will be centered, but I need only
Content
.

Answer

To set the horizontal alignment of the control's content use Control.HorizontalContentAlignment Property like this:

HorizontalContentAlignment="Center"
Comments