如何将标签中的内容居中

How to centered Content from Label

我有一个 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>

但在该变体中,我从所有 Grid 行中得到一个 Label,但它的 Content 位于该行的左侧。 如何使 Content 居中? 如果我输入 HorizontalAlignment="Center" Label 将居中,但我只需要 Content.

要设置控件内容的水平对齐方式,请使用 Control.HorizontalContentAlignment 属性,如下所示:

HorizontalContentAlignment="Center"
HorizontalContentAlignment="Center"