将堆栈布局放置在屏幕中央

时间:2020-01-29 13:54:38

标签: xaml xamarin xamarin.forms cross-platform

我尝试将horizo​​ntaloptions =“ CenterAndExpand”代码插入所有stacklayout路径,但是没有用。

它仍然在左上角:( 有人知道吗?我实际上不使用网格,而是将其留在那里。

我的代码:

<ContentPage.Content>

        <AbsoluteLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
            <Image AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" Source="BackgroundPicture.jpg" Aspect="AspectFill"/>
           <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <StackLayout>
                    <StackLayout Orientation="Horizontal">
                        <local:RoundedEntry x:Name="RegFirstNameEntry" Placeholder="Firstname" WidthRequest="177"></local:RoundedEntry>
                        <local:RoundedEntry x:Name="RegLastNameEntry"  Placeholder="Lastname" WidthRequest="177"></local:RoundedEntry>
                    </StackLayout>
                    <StackLayout Orientation="Horizontal">
                        <local:RoundedEntry x:Name="RegPhoneNumberEntry" Placeholder="Phone" WidthRequest="177" Keyboard="Telephone"></local:RoundedEntry>
                        <local:RoundedEntry x:Name="RegEmailEntry" Placeholder="Email" WidthRequest="177"></local:RoundedEntry>
                    </StackLayout>
                    <StackLayout Orientation="Vertical">
                        <local:RoundedEntry x:Name="RegPasswordEntry" Placeholder="Password" IsPassword="True" ></local:RoundedEntry>
                        <local:RoundedEntry x:Name="RegPasswordAgainEntry" Placeholder="Password" IsPassword="True"></local:RoundedEntry>
                    </StackLayout>
                </StackLayout>
            </Grid>
        </AbsoluteLayout>
    </ContentPage.Content>
</ContentPage>

1 个答案:

答案 0 :(得分:0)

这是因为您的StackLayout默认值为FillAndExpand

要将其居中放置Grid的{​​{1}}中的StackLayout