Question

I want to change from this:

 <Style x:Key="ReportLabelColumn" TargetType="TableColumn">
      <Setter Property="Width" Value="120px" />
 </Style>

To this:

 private Style ReportLabelColumn = new Style(typeof(TableColumn));
 ReportLabelColumn.Setters.Add(new Setter(TableColumn.WidthProperty, 120));

But when I try to run, I get an error saying that:

 {"'120' is not a valid value for the 'System.Windows.Documents.TableColumn.Width' property on a Setter."}

What do I change 120 to, so that it will accept that value as 120px?

Was it helpful?

Solution

TableColumn.Width is a GridLength type property. You need to construct a GridLength object to set the property to.

ReportLabelColumn.Setters.Add(new Setter(TableColumn.WidthProperty, new GridLength(120)));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top