【问题标题】:Xamarin Forms Grid - Row height of "*" in C#?Xamarin Forms Grid - C#中“*”的行高?
【发布时间】:2015-11-07 10:08:07
【问题描述】:

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

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

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

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

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

【问题讨论】:

    标签: c# xamarin xamarin.forms


    【解决方案1】:
    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 };  
    

    【讨论】:

    • 谢谢,无论行的内容是什么,我怎样才能使最后一行扩展到布局的底部?
    • 我确实和@IliaStoilov 有同样的问题,你解决了吗?
    • 只需将行的GridUnitType设置为Auto,并将您放置在网格中的对象的VerticalOptions设置为FillAndExpand即可。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 2017-08-05
    • 2020-10-18
    • 2023-03-20
    • 2017-08-13
    相关资源
    最近更新 更多