【问题标题】:How do I set the Width property onto a TableColumn Style?如何将 Width 属性设置为 TableColumn 样式?
【发布时间】:2012-12-06 18:55:49
【问题描述】:

我想改变这个:

 <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

【问题讨论】:

    标签: c# styles setter tablecolumn


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-02-17
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 1970-01-01
      • 2015-02-20
      • 1970-01-01
      • 2013-05-16
      相关资源
      最近更新 更多