使网格更靠近页面顶部 - XAML

Make a grid to be closer to the top of the page - XAML

我有以下 XAML:

<Grid    HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="1" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="0*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>

                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <PasswordBox HorizontalAlignment="Center" Grid.Row="0" Margin="12" Width="260" Height="32" PlaceholderText="Confirm Password"  BorderBrush="#FF755CB0" BorderThickness="1" Opacity="0.9" x:Name="ConfirmPassword"/>
            <Button Content="Sign-Up" HorizontalAlignment="Center" Margin="12" Grid.Row="1"  Width="260" Height="50" Background="#FF235085" BorderBrush="#FF6749AC" BorderThickness="1" Foreground="White" Opacity="0.9" RequestedTheme="Light" Click="Register_Click"/>
        </Grid>

现在网格在屏幕中央,我希望它高一点,我可以margin,但我不想要任何属性在我的页面中有 pixel。还有其他方法吗? 谢谢

在不使用边距的情况下使网格略高于中心的最简单方法是将其放在另一个网格中。

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="1.2*"/>
    </Grid.RowDefinitions>
    <Grid HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Row="1" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="0*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <PasswordBox HorizontalAlignment="Center" Grid.Row="0" Margin="12" Width="260" Height="32" PlaceholderText="Confirm Password"  BorderBrush="#FF755CB0" BorderThickness="1" Opacity="0.9" x:Name="ConfirmPassword"/>
        <Button Content="Sign-Up" HorizontalAlignment="Center" Margin="12" Grid.Row="1"  Width="260" Height="50" Background="#FF235085" BorderBrush="#FF6749AC" BorderThickness="1" Foreground="White" Opacity="0.9" RequestedTheme="Light" Click="Register_Click"/>
    </Grid>
</Grid>

注意第二行定义

<RowDefinition Height="1.2*"/>

这意味着第二行占用的可用空间 space 比第一行略多,您可以根据自己的需要进行调整。