Pregunta

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?

¿Fue útil?

Solución

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)));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top