How to make DataGrid column stretch from C# code?

前端 未结 2 1360
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 18:54

I\'m creating the columns of a WPF DataGrid in my C# code. I want one of the columns to stretch to the width of the DataGrid automatically. In XAML

相关标签:
2条回答
  • 2021-01-17 19:22

    You're actually using something called a DataGridLength there.

    Try something like this:

    Grid.ColumnDefinitions[0].Width = new DataGridLength(0.2, DataGridLengthUnitType.Star);
    Grid.ColumnDefinitions[1].Width = new DataGridLength(0.8, DataGridLengthUnitType.Star);
    

    That will split the remaining space 80% / 20% between these two columns.

    0 讨论(0)
  • 2021-01-17 19:38

    try this

    DataGrid1.Width = double.NaN;

    0 讨论(0)
提交回复
热议问题