【问题标题】:C# XAML How to modify the dimensions of the rows and the columns of a GridC# XAML 如何修改网格的行和列的尺寸
【发布时间】:2014-01-09 21:41:52
【问题描述】:

我在 XAML 中有下一个代码:

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

我想要的是修改 C# 中的代码。我正在使用下一个代码:

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

使用像素来设置行的高度效果很好,但我非常想使用“*”-thing,比如

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

我怎么能做这样的事情?我在想一个解决方案是获取包含我的网格的控件/页面的高度并制作:

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

还有其他解决方案吗?比这些操作更优雅? (我将使用两行以上,所以最好不要有非常复杂的东西)。

【问题讨论】:

    标签: c# wpf xaml grid height


    【解决方案1】:

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

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

    【讨论】:

    • 非常感谢!我不想使用所有这些操作:)
    猜你喜欢
    • 2019-09-18
    • 2015-11-08
    • 1970-01-01
    • 1970-01-01
    • 2017-09-26
    • 1970-01-01
    • 1970-01-01
    • 2013-09-05
    • 1970-01-01
    相关资源
    最近更新 更多