【问题标题】:Entry height not working on xamarin forms入口高度不适用于 xamarin 表单
【发布时间】: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 网格(或其他布局)中:&lt;Grid Grid.Row=1 RowDefinitions="*, Auto, *"&gt;&lt;Entry Grid.Row="1" .../&gt;&lt;/Grid&gt; 应在外部Entry 中垂直居中Grid的第 1 行。

标签: xamarin xamarin.ios xamarin.android xamarin.forms


【解决方案1】:

条目高度不起作用,因为您已将 1* 作为 RowDefinition。您可以将 RowDefinition 设置为 Auto 并根据需要设置 HeightRequestagaint 每个控件。 还使用 YAlign="Center" 垂直对齐文本。我希望这会有所帮助

【讨论】:

    猜你喜欢
    • 2020-03-14
    • 2017-12-21
    • 1970-01-01
    • 2017-06-05
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    • 2016-02-13
    • 1970-01-01
    相关资源
    最近更新 更多