Edit: Other people have been saying that your data should be a source on the gridview. I believe this would work and be much faster. My solution would work for creating new data with the iteration (like say you wanted the ID to match the spot on the gridview.) It may, however be handy to create a new model for your list item and create some getters for the sake of modular OOP.
In this case I would create a new model for your gridview item (looks like users in this case). So I did something similar in UWP and it ended up looking like this:
ButtonRow = new List<ButtonModel>();
int daysOnButtonRow = 365;
TimeSpan additionalDay = new System.TimeSpan(1);
for (int i = 0; i < daysOnButtonRow; i++)
{
ButtonRow.Add(new ButtonModel(DaysFromToday(i), DaysFromToday(i + 1)));
}
Then the ButtonModel class contained the parameters specific to each button and getters for relevant information I wanted to display on that button.
public class ButtonModel
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public ButtonModel(DateTime _startDate, DateTime _endDate)
{
StartDate = _startDate;
EndDate = _endDate;
}
public string StartDateTruncatedName
{
get { return StartDate.ToString("dddd").Substring(0, 3).ToUpper(); }
}
public string StartDateDayNum
{
get { return StartDate.Day.ToString(); }
}
public string StartDateMonth
{
get { return StartDate.ToString("MMMM").ToUpper(); }
}
}
This can be a lot cleaner and more modular. The example on a listview, but it should work similarly for a gridview. Since you're already working with a populated list, I would suggest using a 'for-in' loop as well for your iteration instead of the standard 'for' loop. This would make it so every time you add an item to the list, it would be added to the gridview.
Hope this helps! :)
sourceto the list of objects, and I write in my xaml the specificfieldNameI would like to show in each column (FieldName is the member variable of my object: Name, ID, Whatever, .. etc)