【发布时间】:2017-10-01 23:48:25
【问题描述】:
我想设置 Xamarin.Forms 项目的下一个代码和平中显示的条目的高度,但它不起作用..
如果我将行的高度设置为:Height="1.3*",条目将占据行的整个高度,但占位符不会垂直对齐,所以我想改用HieghtRequest。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage BackgroundColor="White">
<Grid BackgroundColor="Transparent" RowSpacing="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="5*" />
<RowDefinition Height="4*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" VerticalOptions="FillAndExpand" HorizontalOptions="CenterAndExpand" Padding="0, 30, 0 ,0" RowSpacing="15">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Entry Grid.Row="0" Placeholder="{Binding emailAddress}" VerticalOptions="Center" HeightRequest="70" WidthRequest="330" BackgroundColor="Gray" TextColor="Black" HorizontalOptions="CenterAndExpand"/>
<Entry Grid.Row="1" Placeholder="{Binding password}" HeightRequest="300" VerticalOptions="Center" WidthRequest="330" IsPassword="true" BackgroundColor="Gray" TextColor="Black" HorizontalOptions="CenterAndExpand"/>
<StackLayout Grid.Row="2">
</StackLayout>
<Button Grid.Row="4" BackgroundColor="Red" TextColor="White" HorizontalOptions="CenterAndExpand" Text="{Binding signIn}" HeightRequest="70" WidthRequest="330"/>
</Grid>
<Grid Grid.Row="1">
</Grid>
</Grid>
【问题讨论】:
-
我不想这样做,但我不得不为入口控件进行自定义渲染,现在它似乎可以工作了..
-
对于未来的读者:为了在元素的行为方式上获得更大的灵活性,请将元素包裹在其 OWN 网格(或其他布局)中:
<Grid Grid.Row=1 RowDefinitions="*, Auto, *"><Entry Grid.Row="1" .../></Grid>应在外部Entry中垂直居中Grid的第 1 行。
标签: xamarin xamarin.ios xamarin.android xamarin.forms