0

我想改变这个:

 <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

4

1 回答 1

1

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

ReportLabelColumn.Setters.Add(new Setter(TableColumn.WidthProperty, new GridLength(120)));
于 2012-12-06T19:00:59.860 回答