Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.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# 如何将“宽度”属性设置为TableColumn样式?_C#_Styles_Setter_Tablecolumn - Fatal编程技术网

C# 如何将“宽度”属性设置为TableColumn样式?

C# 如何将“宽度”属性设置为TableColumn样式?,c#,styles,setter,tablecolumn,C#,Styles,Setter,Tablecolumn,我想改变一下: <Style x:Key="ReportLabelColumn" TargetType="TableColumn"> <Setter Property="Width" Value="120px" /> </Style> 但是,当我尝试运行时,会出现一个错误,即: {"'120' is not a valid value for the 'System.Windows.Documents.TableColumn.Width'

我想改变一下:

 <Style x:Key="ReportLabelColumn" TargetType="TableColumn">
      <Setter Property="Width" Value="120px" />
 </Style>
但是,当我尝试运行时,会出现一个错误,即:

 {"'120' is not a valid value for the 'System.Windows.Documents.TableColumn.Width' property on a Setter."}
我应该将
120
更改为什么,以便它接受该值,因为
120px

是一个类型属性。您需要构造一个
GridLength
对象来设置属性

ReportLabelColumn.Setters.Add(new Setter(TableColumn.WidthProperty, new GridLength(120)));
ReportLabelColumn.Setters.Add(new Setter(TableColumn.WidthProperty, new GridLength(120)));