Why is my tree displaying only up to 2 levels? For example, NetworkControl.AddressData.MessageOriginatorID.Value
shows only NetworkControl
as root
You need to recursively add the Children
from the TreeModel
to the TreeViewModel
.
You could make a helper function or extension method for this or just add the logic directly to your 'GetRequestTreeNodesFromModel'
Here is a example that recursively creates your TreeViewModel
collection from the TreeModel
collection
public IEnumerable<TreeViewModel> ToTreeViewModel(IEnumerable<TreeModel> treemodel)
{
foreach (var item in treemodel)
{
yield return new TreeViewModel { Name = item.Name, Children = ToTreeViewModel(item.Children).ToList() };
}
}
Then you can use that in your GetRequestTreeNodesFromModel
function
public List<TreeViewModel> GetRequestTreeNodesFromModel()
{
return ToTreeViewModel(treeModel.GetRequestTreeNodes()).ToList();
}
Result: