Not able to get an idea of what the expected output should be ? Can you draw the tree and post it.
You may have to create a wrapper VM type for the domain type you want to present. say.. MasterPartVM. You can now define a property with the logic for the 2 routes e.g. Children. Your hierararchical data template will always expand the next level using this property.
This will put the onus of finding the right children on your implementation of MasterPartVM.Children - which you seem to have nailed down. Let me know if I have misunderstood the problem..
e.g. In the linked post, you can see that I used a wrapper property to combine Subgroups and Entries to collate a single list.
Here's another example
public class MyPart
{
public string Name { get; set; }
public bool IsRoot { get; set; }
public string[] ChildNames { get; set; }
public IList<MyPart> Children {
get {
if (IsRoot)
return ChildNames.Select(c => new MyPart { Name = c, ChildNames =new[]{c} }).ToList();
else
return new List<MyPart>{new MyPart { Name = "No more children" }};
} }
}
MyPartsCollection = new ObservableCollection<MyPart>();
MyPartsCollection.Add(new MyPart
{
Name = "Root1",
IsRoot = true,
ChildNames = new []{"Item1", "Item2", "Item3"}
});
<TreeView ItemsSource="{Binding MyPartsCollection}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:MyPart}"
ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>