如何使用xaml-xamarin.forms填充布局屏幕?

时间:2017-07-24 22:21:43

标签: xaml mobile xamarin.forms

我有一个网格,我希望它填满屏幕。 我可以使用水平选项吗?例如?

  <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <Button Image="imgteste.png" Grid.Row="0" Grid.Column="0"></Button>
        <Label Text="User name:" Grid.Row="0" Grid.Column="1"></Label>
        <Label Text="User name:" Grid.Row="1" Grid.Column="0"></Label>
        <Label Text="User name:" Grid.Row="1" Grid.Column="1"></Label>
    </Grid>

1 个答案:

答案 0 :(得分:1)

您需要像想象的那样添加HorizontalOptionsVerticalOptions

<Grid HorizontalOptions="Fill"
      VerticalOptions="Fill">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

    <Button Image="imgteste.png" Grid.Row="0" Grid.Column="0"></Button>
    <Label Text="User name:" Grid.Row="0" Grid.Column="1"></Label>
    <Label Text="User name:" Grid.Row="1" Grid.Column="0"></Label>
    <Label Text="User name:" Grid.Row="1" Grid.Column="1"></Label>
</Grid>