How to set row / column definitions in Xamarin.Forms Xaml?

I managed to set the rows and columns from the code, but failed to transfer these settings to xaml:

grid.RowDefinitions = new RowDefinitionCollection { 
    new RowDefinition { Height = new GridLength(1, GridUnitType.Star) } 
};
grid.ColumnDefinitions = new ColumnDefinitionCollection { 
    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } 
};

The following does not work:

<Grid x:Name="grid" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
    <Grid.RowDefinitions>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    ...
</Grid>

From the documentation I only managed to get a C # implementation

+4
source share
2 answers

I also get the same behavior (neither fill nor expand) for a single-cell grid (1 row / column, although I'm not sure why we need a single-cell grid in full screen size), but it seems to work fine for nets 2 x 2, 3 x 3 (have not tried others yet).

Height = " Width =" " Xamarin Forms, , WPF, , .

 <ContentPage.Content>
    <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
    <Grid.RowDefinitions>
    <RowDefinition Height="*"></RowDefinition>
    <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"></ColumnDefinition>
    <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>

    <Button Grid.Row="0" Grid.Column="0" Text="1"></Button>
    <Button Grid.Row="1" Grid.Column="1" Text="2"></Button>
    </Grid>
</ContentPage.Content>
+7

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>
  <Label Text="Top Left" Grid.Row="0" Grid.Column="0" />
  <Label Text="Top Right" Grid.Row="0" Grid.Column="1" />
  <Label Text="Bottom Left" Grid.Row="1" Grid.Column="0" />
  <Label Text="Bottom Right" Grid.Row="1" Grid.Column="1" />
</Grid>
0

Source: https://habr.com/ru/post/1545282/


All Articles