为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
胡说叔叔 2022-12-04 10:32:44
我正在学习 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">使两个按钮位于屏幕底部,但它显示在屏幕中间。如何解决这个问题呢?
查看完整描述

1 回答

?
肥皂起泡泡

TA贡献1829条经验 获得超6个赞

下面的代码将为您工作,将 VerticalOptions="FillAndExpand" 添加到 Grid 并提供百分比高度。


<?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 VerticalOptions="FillAndExpand">

                <Grid.RowDefinitions>

                    <RowDefinition Height="1*" />

                    <RowDefinition Height="1*" />

                    <RowDefinition Height="1*" />

                    <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" 

VerticalOptions="EndAndExpand" Text="Cancel" Clicked="Cancel_Clicked"></Button>

</Grid>   

</StackLayout>

</ContentPage>


查看完整回答
反对 回复 2022-12-04
  • 1 回答
  • 0 关注
  • 73 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号