【问题标题】:WPF c# datagrid set individual row heightWPF c# datagrid设置单独的行高
【发布时间】:2014-06-20 06:21:27
【问题描述】:

我对 WPF 和 C# 很陌生。 我正在尝试创建一个数据网格,我可以在其中以编程方式设置各个行的高度。

似乎可以同时更改所有行的高度,但我希望各行的高度彼此不同。

有谁知道实现这一点的方法吗? (我在想我可以将行高设置为自动,并在未使用的列中放置一个不可见的 TextBox。我可以通过编程方式更改未使用的 TextBox 的高度。)

【问题讨论】:

    标签: c# wpf datagrid


    【解决方案1】:

    最简单的事情可能是在DataGrid.LoadingRow 事件中处理这个问题,该事件在一行被实例化后立即引发。

    为此,只需在 xaml 代码中将事件处理程序添加到您的数据网格:

    <DataGrid LoadingRow="DataGrid_LoadingRow"></DataGrid>
    

    并在您的代码中声明此事件处理程序以通过 Height 属性单独管理行高:

    private void DataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
    {
        DataGridRow row = e.Row;
        row.Height = 50; //put your height here
    }
    

    【讨论】:

      【解决方案2】:

      埃克鲁格,

      非常感谢您的回复。

      但是,您的技术仅在创建数据网格时发生。 我需要一些可以在不同时间调用的东西,这样我就可以定期调整行的大小。

      我一直在寻找,这是我找到的解决方案。

      干杯。

      • 马特

        private void resizeDataGridRowHeight() {
            int a = boundDataGrid.Items.Count;
            int calibrationRowHeight = 28;
            for (int i = 0; i < a; i++) {
                myRowHeight = ListofObjectsThatEachRepresentAParameter.ListOfDataTableRows[i].ListOfCalibrationRows.Count * calibrationRowHeight;
                DataGridRow row = boundDataGrid.ItemContainerGenerator.ContainerFromIndex(i) as DataGridRow;
                row = boundDataGrid.ItemContainerGenerator.ContainerFromIndex(i) as DataGridRow;
                row.Height = myRowHeight;
            }
        }
        

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-28
        • 2010-12-30
        • 2010-11-13
        • 2014-06-15
        • 2013-12-27
        • 1970-01-01
        • 1970-01-01
        • 2011-05-11
        相关资源
        最近更新 更多