我想创建一个网格,它的第一个单元格是正方形的,即它的高度等于它的宽度,这是由屏幕宽度决定的。我想像下面的东西,但它没有工作。
<Grid RowDefinitions ="{DeviceDisplay.Current.MainDisplayInfo.Width}, *"> ... ... </Grid>
1cklez4t1#
是的,您可以在代码中实现这一点。我创建了一个demo,可以参考下面的代码:
public class GridPageCS : ContentPage { public GridPageCS() { Grid grid = new Grid { RowDefinitions = { new RowDefinition { Height = new GridLength(DeviceDisplay.Current.MainDisplayInfo.Width, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(100) } }, ColumnDefinitions = { new ColumnDefinition() } }; grid.Children.Add(new BoxView { Color = Colors.Green }); grid.Children.Add(new Label { Text = "Row 0, Column 0", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center }); Title = "Basic Grid demo"; Content = grid; } }
1条答案
按热度按时间1cklez4t1#
是的,您可以在代码中实现这一点。
我创建了一个demo,可以参考下面的代码: