I am trying to programmically add TextBox
in my Grid.
Here is my code:
private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
var input= await OneListDataSource.GetItemAsync((string)e.NavigationParameter);
foreach (string item in input.getItems()) {
TextBox textBox = new TextBox();
textBox.Text = item;
grid.RowDefinitions.Add(new RowDefinition());
grid.Children.Add(textBox);
}
}
And in my xaml:
<Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
</Grid>
But when I run it in simulator, I only see 1 row and all the item seems overlapping each other.
I tried remove Grid.Row
in my xaml file, but I don't see it make any difference.
Updated:
Thanks for the answers, I almost get this to work. Now my question is Why I need to add a new RowDefintion() everything I add a new children(), can I do it without RowDefinitions.Add(new RowDefinition()) for each row?
foreach (string item in input.getItems()) {
TextBox textBox = new TextBox();
textBox.Text = item;
grid.RowDefinitions.Add(new RowDefinition()); // why I need to do this everytime I add a new TextBox?
Grid.SetRow(textBox, i++);
Grid.SetColumn(textBox, 0);
grid.Children.Add(textBox);
}