gpt4 book ai didi

c# - Xamarin Forms Grid - C# 中的行高为 "*"?

转载 作者:太空狗 更新时间:2023-10-29 17:35:46 25 4
gpt4 key购买 nike

我知道您可以通过这种方式在 XAML 中使用“*”设置行高:

 <RowDefinition Height="Auto" />
<RowDefinition Height="*" />

但在 C# 中相同的表达式返回错误:

new RowDefinition { Height = new GridLength("*", GridUnitType.Auto) },

所以我的问题是如何在 C# 中将网格的行高设置为“*”?

最佳答案

var grid = new Grid ();
grid.RowDefinitions.Add (new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add (new RowDefinition { Height = new GridLength (1, GridUnitType.Star) });

var stacklayout1 = new StackLayout { HeightRequest = 100, BackgroundColor = Color.Red };
var stacklayout2 = new StackLayout { BackgroundColor = Color.Blue };

Grid.SetRow (stacklayout2, 1);

grid.Children.Add (stacklayout1);
grid.Children.Add (stacklayout2);

MainPage = new ContentPage { Content = grid };

Screenshot of the above layout on iOS

关于c# - Xamarin Forms Grid - C# 中的行高为 "*"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32005192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com