myGrid.RowDefinitions = new RowDefinitionCollection(); for (int myCount = 0; myCount < amoutOfRows; myCount++) { myGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); }