I have a very nested entity structure like this:
DataObject > Universities (List) > Colleges (List) > Students (List) > Projects (List)
I want to bind a TreeView with directly my DataObject as:
myTreeView.ItemSource = DataObject.Universities;
DataTemplate dataTemplate = new DataTemplate();
dataTemplate.DataType = typeof(Student);
FrameworkElementFactory spFactoryDeliverable = new FrameworkElementFactory(typeof(TextBlock));
spFactoryDeliverable.Name = "spFactoryDeliverable";
spFactoryDeliverable.SetBinding(TextBlock.TextProperty, new Binding("Colleges/Students/Name"));
dataTemplate.VisualTree = spFactoryDeliverable;
rdTreeDeliverables.ItemTemplate = dataTemplate;
to display nodes with Students’ Names. But the problem is that- It will display the name of only single College’s student names. It will not display the records of second or any further college record.
Any suggestion/idea?
{Binding Path=/} shows the current item from a list, it does not iterate over the list in any way – if you want to show nested lists you need some type of nested data templates (either HierarchicalDataTemplate or a DataTemplate with an ItemsControl in it – depending on the control this template will be used with).
You should also think about “flattening” the list in code before binding if you want to use a control that does not work with hierarchies.