Terco
Terco

Reputation: 920

Setting ColumnDefinitions in code

I'm wondering if there is a way to set a ColumnDefinition Width to * in code, like you can in the xaml file. When trying to set in code GridLength just has the Auto has an option.

<ColumnDefinition Width="*"/>

Thanks for any help.

Upvotes: 20

Views: 11178

Answers (1)

Chris Taylor
Chris Taylor

Reputation: 53729

You will need to create an instance of the GridLength data type and specify GridUnitType.Star

col.Width = new GridLength(1, GridUnitType.Star);

Upvotes: 36

Related Questions