'Labels not appearing in Grid despite being children of it

I'm relatively new to Xamarin and I've been trying to programmatically add labels to a grid but each time they don't appear on the screen. Here's the code :

for (int line = 0; line < NB_ROWS; line++)
{
    for (int col = 0; col < NB_COLS; col++)
    {
        Label label = new Label()
        {
            HeightRequest = tileHeight,
            WidthRequest = tileWidth,
            FontSize = 25,
            VerticalTextAlignment = TextAlignment.Center,
            HorizontalTextAlignment = TextAlignment.Center,
            BackgroundColor = Color.FromHex("#94a5ae"),
            Text = "0",
        };
        gridTiles.Children.Add(label, col, line);
    }
}

While debugging, girTiles.Children does have the labels in it, but the end result is always blank. If I try to add labels directly in the grid with XAML, it does work.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source