【问题标题】:How to set WPF component height to "*" in code?如何在代码中将 WPF 组件高度设置为“*”?
【发布时间】:2012-07-11 14:22:58
【问题描述】:

我想在代码中动态地将组件高度设置为"*"。我该怎么做?

我知道如何将其设置为定义的值:

DataGrid.Height = "500";

以及如何设置为“自动”:

DataGrid.Height = Double.NaN;

【问题讨论】:

    标签: wpf height code-behind


    【解决方案1】:

    您也可以使用带有GridUnitType 的列定义/行定义来执行此操作,例如:

    RowDefinition rd = new RowDefinition();
    rd.Height = new GridLength(1.0, GridUnitType.Star);
    grid.RowDefinitions.Add(rd);
    

    另见:Grid Star-Size in code behind

    【讨论】:

      【解决方案2】:

      星号大小仅适用于极少数组件,Grid 本身不是其中之一。 GridLengtha constructor ,它以 sizing sheme 的类型作为参数。

      如果要拉伸组件,请不要为 Width/Height 设置任何值,并确保 Horizontal/VerticalAlignmentStretch

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-04
        • 2015-06-02
        • 2014-06-20
        • 1970-01-01
        • 2012-02-24
        • 2011-08-06
        相关资源
        最近更新 更多