Longtime ASP.NET developer, I'm pretty new to Xamarin.
I have a Grid that I am constructing in code-behind. When I change it in code-behind, it does not visually change in the UI. Basically I want to display the data in a simple grid as that data gets collected.
Here's my XAML:
<ScrollView HeightRequest="100">
<Grid x:Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Text="TL" Grid.Row="0" Grid.Column="0" />
<Label Text="TR" Grid.Row="0" Grid.Column="1" />
<Label Text="BL" Grid.Row="1" Grid.Column="0" />
<Label Text="BR" Grid.Row="1" Grid.Column="1" />
</Grid>
</ScrollView>
I put in four cells just for testing. These four cells display initially but never change. Here's my code-behind that is executed on a button-click:
private void updateGrid(List<MyStringData> data) {
grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); //Field1
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); //Field2
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); //Field3
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); //Field4
int i = 0;
foreach (MyStringData r in data) {
gridPitches.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
gridPitches.Children.Add(new Label() { Text = r.Field1 }, 0, i);
gridPitches.Children.Add(new Label() { Text = r.Field2 }, 1, i);
gridPitches.Children.Add(new Label() { Text = r.Field3 }, 2, i);
gridPitches.Children.Add(new Label() { Text = r.Field4 }, 3, i);
i++;
}
}
This method apparently does nothing. Do I need to tell the grid or view to redraw or something?