Programmatically setting the width of a grid column with * in WPF

前端 未结 3 1016
眼角桃花
眼角桃花 2020-12-25 10:57

I want to programmatically configure a wpf grid.

I want to be able to set a grid with 2 columns, the first taking up 20% of available space, the second taking up 80

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-25 11:28

    Grid grid = new Grid();
    ColumnDefinition c1 = new ColumnDefinition();
    c1.Width = new GridLength(20, GridUnitType.Star);
    ColumnDefinition c2 = new ColumnDefinition();
    c2.Width = new GridLength(80, GridUnitType.Star);
    grid.ColumnDefinitions.Add(c1);
    grid.ColumnDefinitions.Add(c2);
    

提交回复
热议问题