Reputation: 754
So I'm creating columns dynamically for a Grid layout in Silverlight (V3.0, C#):
LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
and you can specific that the width of the column be "auto" with
LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
But how to you set it to be "*" (share with with other columns)?
I know you can set this in the XAML, but how do you do it in code?
Upvotes: 9
Views: 6611
Reputation: 74832
Pass a GridLength with a GridUnitType of Star:
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) };
Bonus is that this technique also supports proportional spacing i.e. the equivalent of XAML 2*, 3*, etc.
Upvotes: 20