Xaml 在网格UWP中对中StackPanel

Xaml 在网格UWP中对中StackPanel,xaml,win-universal-app,uwp-xaml,Xaml,Win Universal App,Uwp Xaml,对于我的通用Windows应用程序,我正在尝试将StackPanel置于页面的网格中心,如图所示。但是当我运行下面的代码时,有三个按钮位于底部的中心位置。有什么问题吗 MainPage.xaml: <Page> <Grid Background="WhiteSmoke"> <Grid.RowDefinitions> <RowDefinition Height="*"/> &l

对于我的通用Windows应用程序,我正在尝试将StackPanel置于页面的网格中心,如图所示。但是当我运行下面的代码时,有三个按钮位于底部的中心位置。有什么问题吗

MainPage.xaml:

<Page>
    <Grid Background="WhiteSmoke">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid VerticalAlignment="Top">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10 0">
                <Button x:Name="BackButton" Height="50" Width="150" Background="{x:Null}" BorderBrush="White">
                    <StackPanel Orientation="Horizontal">
                        <Viewbox MaxHeight="50" MaxWidth="50">
                            <SymbolIcon Symbol="Back" Foreground="White"></SymbolIcon>
                        </Viewbox>
                        <TextBlock Foreground="White" VerticalAlignment="Center" Margin="10" FontSize="20" FontWeight="Bold">Back</TextBlock>
                    </StackPanel>
                </Button>
            </StackPanel>
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
                <Button Width="150" Height="50" Content="Page 1" FontSize="20" FontWeight="Bold"/>
                <Button Width="150" Height="50" Content="Page 2" Foreground="#FFFFFF" FontSize="20" FontWeight="Bold"/>
                <Button Width="150" Height="50" Content="Page 3" Foreground="#FFFFFF" FontSize="20" FontWeight="Bold"/>
            </StackPanel>
            <Grid Width="150" Height="5" Background="#FFFFFF" HorizontalAlignment="Center" Margin="240" />
        </Grid>
        <Frame
            Grid.Row="1"
            x:Name="Frame">
        </Frame>
    </Grid>
</Page>

返回
第1.xaml页

<Page>
    <Grid Background="WhiteSmoke">
        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
            <Button Height="150" Width="300" Margin="5" FontWeight="Bold" FontSize="20">
                <StackPanel Orientation="Vertical">
                    <TextBlock Foreground="White" VerticalAlignment="Center" Margin="10" Padding="0">Page 1</TextBlock>
                </StackPanel>
            </Button>
            <Button Height="150" Width="300" Margin="5" FontWeight="Bold" FontSize="20">
                <StackPanel Orientation="Vertical">
                    <TextBlock Foreground="White" VerticalAlignment="Center" Margin="10" Padding="0">Page 2</TextBlock>
                </StackPanel>
            </Button>
            <Button Height="150" Width="300" Margin="5" FontWeight="Bold" FontSize="20">
                <StackPanel Orientation="Vertical">
                    <TextBlock Foreground="White" VerticalAlignment="Center" Margin="10" Padding="0">Page 3</TextBlock>
                </StackPanel>
            </Button>
        </StackPanel>
    </Grid>
</Page>

第1页
第2页
第3页
编辑: 解决办法是:

<Grid.RowDefinitions>
    <RowDefinition Height="0.1*"/>
    <RowDefinition Height="*"/>
</Grid.RowDefinitions>


删除网格中的
verticalignment=“Top”
解决方案是设置合理的行高比。并从放置在第0行区域的网格中删除
VerticalAlignment=“Top”

<Grid.RowDefinitions>
    <RowDefinition Height="0.1*"/>
    <RowDefinition Height="*"/>
</Grid.RowDefinitions>

有关更多信息,请参阅
NavigationView

如果您已经解决了问题,请在下面发布您的答案,请避免在问题中发布答案。实际上,您只需切换最顶部网格中的行定义。首先是高度=自动,第二个*我不认为将高度设置为0.1*(相对值)是个好主意。它应该是绝对值或自动值,因为页眉的高度不依赖于父级(窗口)height@Liero,是的,但是op给出了他的解决方案,我只是帮你转到下面。对于他的要求,更好的方法是在顶部区域制作NavigationView,然后将框架放在下面。
<NavigationView x:Name="nvSample" Header="This is Header Text" PaneDisplayMode="Top">
    <NavigationView.MenuItems>
        <NavigationViewItem  Content="Menu Item1" Tag="SamplePage1" />
        <NavigationViewItem  Content="Menu Item2" Tag="SamplePage2" />
        <NavigationViewItem  Content="Menu Item3" Tag="SamplePage3" />
        <NavigationViewItem  Content="Menu Item4" Tag="SamplePage4" />
    </NavigationView.MenuItems>
    <Frame x:Name="contentFrame"/>
</NavigationView>