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)));