How to GetAllChildren from SelectedItem

In my program, I would like to get all the children of the parent node so that I can add a new node to it. In the past, I used this approach:

//This gets all the children of a parent node depending on it DisplayName
var node = ObservableCollection.GetAllChildren(x => x.Children).Distinct().ToList().First(x => x.DisplayName == nameOfNode);
node.Children.Add(CreateNode(newNodeName));

Now I would like GetAllChildrenfrom my property SelectedItem, which is fully functional. Can this be done using the method GetAllChildren? If so, how?

Addition 1:

The My property SelectedItemis of type ViewModel. ObservableCollectionalso has a type ViewModel, so basically SelectedItemthe program selected by ViewModel is indicated.

Addition 2:

I can’t just add a Node parent. I have to check how many children there are for other reasons in this program before adding.

+3
source share
1 answer

, , , , node, SelectedItem, node. SelectedItem.Add ? .

Linq Count():)

+1

All Articles