Student class
public class Student
{
string name;
List<SubjectInfo> subjectInfoList;
....
}
List<SubjectInfo> List can have different number of SubjectInfo objects for different students.
SubjectInfo class
public class SubjectInfo
{
string subjectCode;
int marks;
...
}
I want to display student object detail on a window. Since List have different number of object count I generated these from code behind.
int i = 10;
foreach (SubjectInfo info in student.SubjectInfoList)
{
TextBox tb = new TextBox();
tb.Width = 200;
tb.Height = 20;
tb.Margin = new Thickness(10, i, 0, 0);
StudentDataGrid.Children.Add(tb);
i += 60;
}
I would like to bind this List list from code behind. But I have no idea of doing that.
I want to bind marks property of student.SubjectInfoList
Please help me with binding list object properties from codebehind.
EDIT
This is the sample student object;
Student student = new Student("Joe", new List<SubjectInfo>() { new SubjectInfo("Subject1", 50), new SubjectInfo("Subject2", 70)});
My window should like this;
NOTE if student doing 4 subjects total TextBox count is 5.
Pure XAML solution:
But to have it work you have to transform your fields to public properties:
and:
UPDATE
XAML:
The code: