1

I want to set a component height to "*" dynamically in code. How can I do that?

I know how to set it to a defined value:

DataGrid.Height = "500";

And how to set to "Auto":

DataGrid.Height = Double.NaN;
Guilherme Campos
  • 369
  • 7
  • 20

2 Answers2

1

Star sizing only exists for very few components, the Grid itself is not one of them. GridLength has a constructor which takes the type of the sizing sheme as parameter.

If you want a component to stretch do not set any value for Width/Height and make sure the Horizontal/VerticalAlignment is Stretch.

H.B.
  • 166,899
  • 29
  • 327
  • 400
1

You can also do this using the columndefinitions/rowdefinitions with GridUnitType, for example :

RowDefinition rd = new RowDefinition();
rd.Height = new GridLength(1.0, GridUnitType.Star);
grid.RowDefinitions.Add(rd);

See also : Grid Star-Size in code behind

Community
  • 1
  • 1
Alucia
  • 11
  • 2