I am trying to make a treeview that represents data from a file. The file data has data packets organized into three different sections: Header Info, Operation Header, and Operation Data. The packets in Header Info and Operation Header are one level deep, while the packets in Operation Data are grouped into lists so I thought it'd be easier to organize by making it go an extra level. That way you could pop open Data, see the lists, and pop those open to see individual data packets.
This is my xaml:
<TreeView ItemsSource="{Binding TreeViewItems}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding TreeNodes}">
<TextBlock Text="{Binding Name}" />
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Name}" />
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate>
<TextBlock Text="{Binding DataPackets.ItemName}"/>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
And here is the code we are trying to bind to the hierarchical datatemplates:
var childData = new Children();
result.OperationData.ToList().ForEach(x => childData.DataPackets.Add(x));
if (result.HeaderInfo.Any())
{
TreeViewItems.Add(new TreePair() { TreeNodes = result.HeaderInfoProperties.ToList(), Name = "Header Info" });
}
TreeViewItems.Add(new TreePair() { TreeNodes = result.OperationHeaderProperties.ToList(), Name = "Operation Header" });
TreeViewItems.Add(new TreePair() { TreeNodes = result.OperationDataProperties.ToList(), Children = new List<Children> {childData}, Name = "Operation Data" });
and the classes
public class TreePair
{
public TreePair()
{
TreeNodes = new List<PropertyInfo>();
Children = new List<Children>();
}
public List<Children> Children { get; set; }
public List<PropertyInfo> TreeNodes { get; set; }
public string Name { get; set; }
}
public class Children
{
public Children()
{
DataPackets = new List<DataPacketBase>();
}
public string Name { get; set; }
public List<DataPacketBase> DataPackets { get; set; }
}
I have the data packets for Header info and operation header showing up, as well as the list names for Operation data but none of the child packets show up. They exist in the Children.DataPackets object.
This is throwing in the output window: BindingExpression path error: 'Children' property not found on 'object'
The second TextBlock is correct, but the Children ItemSource Is not being found, but the list is being filled with items.

Children Name property Missing From Second Level
