3
votes

I have a grid that contains several controls in rows of a grid. I have the RowDefinitions set so that each row in the grid has a height of "*" in the XAML, so that all the controls have the same amount of room available to them.

I have a configuration screen that allows the user to disable/enable some of the controls. If a control is disabled, I change the Visibility to Collapsed and set its row height in the grid to zero. This works great on application start up.

The issue is that if the user goes into the settings screen and re-enables controls (that were previously hidden) while the application is already running, I'm not sure how to set the control's grid column back to the correct size, and make it re-distribute all the available height among the new (increased) number of rows.

Is there a way to set all the heights back to "*" in C# code, and have WPF do the redistribution?

If not, any other ideas, other than doing the math myself and manually setting the row heights, or restarting the whole application?

1

1 Answers

2
votes

You can set the star values like this:

rowDef.Height = new GridLength(1, GridUnitType.Star);

See also: http://msdn.microsoft.com/en-us/library/system.windows.gridunittype.aspx