I have the following ListView-
<ListView x:Name="listViewm" ItemsSource="{ Binding Rows }">
<ListView.Header >
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Text="Name" Grid.Column="3" FontSize="Medium" />
<Label Text="Age" Grid.Column="2" FontSize="Medium" />
<Label Text="DOB" Grid.Column="1" FontSize="Medium" />
</Grid>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--I need my Row values here-->
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I need to create a row for each entry I have in a list and add it to the grid dynamically -
protected override void OnAppearing()
{
CreateGrid();
}
public ObservableCollection<Row> Rows { get; set; }
public class Row
{
public string Name { get; set; }
public string Age { get; set; }
public string DOB { get; set; }
}
public void CreateGrid()
{
Rows = new ObservableCollection<Row>();
Rows.Clear();
foreach(var entry in entryList) { // entryList just contains values I use to populate row info
var row = new Row();
row.Name = entry.name;
row.Age = entry.age;
row.DOB = entry.dob;
Rows.Add(row);
}
}
The itemSource is not binding so no new rows are being create, I tried removing ItemsSource="{ Binding Rows }" in the XAML and using listViewm.ItemsSource = Rows in the code behind instead however this also did not work.
So if entryList had 3 test entries for John, Bob and Bill the table should look like -
+----------------+
| Name Age DOB |
+----------------+
| John 31 06/09 |
| Bill 32 07/10 |
| Bob 34 08/11 |
+----------------+