简体   繁体   English

C#XAML如何修改网格的行和列的尺寸

[英]C# XAML How to modify the dimensions of the rows and the columns of a Grid

I have the next code in XAML : 我在XAML中有下一个代码:

    <Grid.RowDefinitions>
        <RowDefinition Height="6*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

What I want is to modify the code in C#. 我想要的是修改C#中的代码。 I'm using the next code : 我正在使用下一个代码:

 ListBoxGrid.RowDefinitions[0].Height = new GridLength(100); 
 ListBoxGrid.RowDefinitions[1].Height = new GridLength(800); 

Using pixels to set the Height of the rows works just fine, but I would very much like to use the "*"-thing, something like 使用像素设置行的高度工作得很好,但我非常想使用“*” - 东西,像

 ListBoxGrid.RowDefinitions[0].Height = "*";
 ListBoxGrid.RowDefinitions[1].Height = "3*";

How can I do something like that ? 我怎么能这样做? I'm thinking that a solution would be to get the Height of the control/page that contains my grid and make : 我认为解决方案是获取包含我的网格的控件/页面的高度并制作:

 ListBoxGrid.RowDefinitions[0].Height = ControlHeight/4;
 ListBoxGrid.RowDefinitions[1].Height = ControlHeight/4*3;

Is there another solution ? 还有其他解决方案吗? More elegant than these operations ? 比这些操作更优雅? (I will use more than two rows, so it would be nice to not have something very complicated). (我将使用两行以上,所以没有非常复杂的东西会很好)。

你可以这样做,检查GridLength的其他构造函数

myGrid.RowDefinitions[0].Height = new GridLength(1, GridUnitType.Star);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM