0
votes

I wanted to have most rows defined xaml code and only one added programmatically in code-behind, but I am not able to do it.

Here is my XAML simplified code:

<Grid x:Name="gridTest">
    <Grid.RowDefinitions>
        <RowDefinition Height="auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="auto" />
    </Grid.RowDefinitions>
</Grid>

<Label Grid.Row="0" Text="row 0"></Label>

<Label Grid.Row="1" Text="row 1"></Label>

And in my code-behind:

gridTest.Children.Add(new Label { Text = "row 2" }, 0, 2);

The output is just "row 2"

Is this really impossible or am I missing something?

Tks

1

1 Answers

2
votes

your XAML labels need to be within your <Grid></Grid> tags

<Grid x:Name="gridTest">
    <Grid.RowDefinitions>
        <RowDefinition Height="auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="auto" />
    </Grid.RowDefinitions>
  <Label Grid.Row="0" Text="row 0"></Label>
  <Label Grid.Row="1" Text="row 1"></Label>
</Grid>