Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在代码中设置列定义_C#_Wpf_Grid_Width - Fatal编程技术网

C# 在代码中设置列定义

C# 在代码中设置列定义,c#,wpf,grid,width,C#,Wpf,Grid,Width,我想知道是否有一种方法可以在代码中将ColumnDefinition宽度设置为*,就像在xaml文件中一样。当试图在代码中设置GridLength时,Auto有一个选项 <ColumnDefinition Width="*"/> 谢谢您的帮助。您需要创建GridLength数据类型的实例,并指定GridUnitType.Star col.Width = new GridLength(1, GridUnitType.Star); 有趣。谢谢你的帮助。太棒了!你是我的英雄!

我想知道是否有一种方法可以在代码中将ColumnDefinition宽度设置为*,就像在xaml文件中一样。当试图在代码中设置GridLength时,Auto有一个选项

<ColumnDefinition Width="*"/>


谢谢您的帮助。

您需要创建
GridLength
数据类型的实例,并指定
GridUnitType.Star

col.Width = new GridLength(1, GridUnitType.Star);

有趣。谢谢你的帮助。太棒了!你是我的英雄!