如何使用网格行和列定义来定位按钮?

How to position a button using grid row and column definitions?

我已经设置了一个 Windows Phone 8.1 项目,现在我正在尝试放置一个按钮,在靠近布局底部的水平居中位置。

到目前为止,我已经想出了以下方法来使按钮在布局上居中,但是 Grid.Row 设置似乎没有像我预期的那样对垂直定位产生任何影响。

有谁知道如何将按钮定位到屏幕底部?目前它在屏幕的中央但在屏幕的中间,需要朝向屏幕的底部。

<Page x:Class="LC_Points.MainPage"
      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:local="using:LC_Points"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
      DataContext="{Binding Source={StaticResource Locator},
                            Path=MainViewModel}"
      mc:Ignorable="d">
    <Grid>
        <Button Grid.Row="2"
                Content="Calculate"
                HorizontalAlignment="Center"/>
    </Grid>
</Page>

在设置元素的 Grid.Row 属性 之前,首先您必须定义网格的行。

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <Button Grid.Row="1" Content="Click Me!" />
</Grid>

如果您更改 RowDefinitionsHeight 属性,您可以轻松定位 Button ]垂直。

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="90*"></RowDefinition>
        <RowDefinition Height="10*"></RowDefinition>
    </Grid.RowDefinitions>
    <Button Grid.Row="1" Content="Click Me!" />
</Grid>

10* 表示 Grid 的 10%。星星的总和必须等于 100。