猿问

Xamarin布局问题,如何在屏幕底部制作拖车按钮

我正在学习 Xamarin 的布局并面对以下代码:


<?xml version="1.0" encoding="utf-8" ?>

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"

             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

             xmlns:local="clr-namespace:MyApp.Validators"

             x:Class="MyApp.MainPage">

    <StackLayout HorizontalOptions="Fill"  >

        <Grid>

            <Grid.RowDefinitions>

                <RowDefinition Height="*" ></RowDefinition>

                <RowDefinition Height="*"></RowDefinition>

                <RowDefinition Height="*"></RowDefinition>

            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>

                <ColumnDefinition  ></ColumnDefinition>

            </Grid.ColumnDefinitions>

            <Grid Grid.Row="0" Grid.Column="0">

                <Grid.RowDefinitions>

                    <RowDefinition Height="*" ></RowDefinition>

                    <RowDefinition Height="*"></RowDefinition>

                    <RowDefinition Height="*"></RowDefinition>

                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>

                    <ColumnDefinition></ColumnDefinition>

                </Grid.ColumnDefinitions>

                <Entry x:Name="Username" Grid.Row="0" Placeholder="Username" PlaceholderColor="Blue">

                    <Entry.Behaviors>

                        <local:UsernameValidatorBehavior></local:UsernameValidatorBehavior>

                    </Entry.Behaviors>

                </Entry>

                <Entry x:Name="Password" Grid.Row="1" Keyboard="Numeric" Placeholder="Password" PlaceholderColor="Blue">

                    <Entry.Behaviors>

                        <local:PasswordValidatorBehavior></local:PasswordValidatorBehavior>

                    </Entry.Behaviors>

                </Entry>


我的问题是我尝试使用


<Grid VerticalOptions="End" Grid.Row="1" Grid.Column="0">


使两个按钮位于屏幕底部,但它显示在屏幕中间。如何解决这个问题呢?

胡说叔叔
浏览 74回答 1
1回答

肥皂起泡泡

下面的代码将为您工作,将 VerticalOptions="FillAndExpand" 添加到 Grid 并提供百分比高度。<?xml version="1.0" encoding="utf-8" ?><ContentPage xmlns="http://xamarin.com/schemas/2014/forms"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:local="clr-namespace:MyApp.Validators"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x:Class="MyApp.MainPage"><StackLayout HorizontalOptions="Fill">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Grid VerticalOptions="FillAndExpand">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Grid.RowDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition Height="1*" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition Height="1*" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition Height="1*" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition Height="7*" /></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="*"></ColumnDefinition><ColumnDefinition Width="*"></ColumnDefinition></Grid.ColumnDefinitions><Entry x:Name="Username" Grid.Row="0" Grid.ColumnSpan="2" Placeholder="Username" PlaceholderColor="Blue"><Entry.Behaviors><local:UsernameValidatorBehavior></local:UsernameValidatorBehavior></Entry.Behaviors></Entry><Entry x:Name="Password" Grid.Row="1" Grid.ColumnSpan="2" Keyboard="Numeric" Placeholder="Password" PlaceholderColor="Blue"><Entry.Behaviors><local:PasswordValidatorBehavior></local:PasswordValidatorBehavior></Entry.Behaviors></Entry><Entry x:Name="Email" Grid.Row="2" Grid.ColumnSpan="2" Placeholder="Email" PlaceholderColor="Blue"><Entry.Behaviors><local:EmailValidatorBehavior></local:EmailValidatorBehavior></Entry.Behaviors></Entry><Button x:Name="Submit" Grid.Row="3" Grid.Column="0" VerticalOptions="EndAndExpand" Text="Submit" Clicked="OnButtonClicked"></Button><Button x:Name="Cancel" Grid.Row="3" Grid.Column="1"&nbsp;VerticalOptions="EndAndExpand" Text="Cancel" Clicked="Cancel_Clicked"></Button></Grid>&nbsp; &nbsp;</StackLayout></ContentPage>
随时随地看视频慕课网APP
我要回答