我想改变这一点:
<Style x:Key="ReportLabelColumn" TargetType="TableColumn">
<Setter Property="Width" Value="120px" />
</Style>
对此:
private Style ReportLabelColumn = new Style(typeof(TableColumn));
ReportLabelColumn.Setters.Add(new Setter(TableColumn.WidthProperty, 120));
但是当我试图跑步时,我得到一个错误说:
{"'120' is not a valid value for the 'System.Windows.Documents.TableColumn.Width' property on a Setter."}
我将120
更改为什么,以便将该值接受为120px
?
答案 0 :(得分:1)
TableColumn.Width
是GridLength
类型的属性。您需要构造一个GridLength
对象来将属性设置为。
ReportLabelColumn.Setters.Add(new Setter(TableColumn.WidthProperty, new GridLength(120)));