如何将Width属性设置为TableColumn样式?

时间:2012-12-06 18:55:50

标签: c# styles setter tablecolumn

我想改变这一点:

 <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

1 个答案:

答案 0 :(得分:1)

TableColumn.WidthGridLength类型的属性。您需要构造一个GridLength对象来将属性设置为。

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