在我的程序中,我想获取父节点的所有子节点,以便我可以向其中添加新节点。过去我使用了以下方法:
//This gets all the children of a parent node depending on it's DisplayName
var node = ObservableCollection.GetAllChildren(x => x.Children).Distinct().ToList().First(x => x.DisplayName == nameOfNode);
node.Children.Add(CreateNode(newNodeName));
现在,我想基于我的
SelectedItem
属性(功能完整)获取其全部子项,使用GetAllChildren
方法是否可行?如果可以,请问如何操作?
附加说明1:
SelectedItem
属性的类型为ViewModel。ObservableCollection也是ViewModel类型,所以SelectedItem
告诉程序哪个ViewModel被选中了。
附加说明2:
我不能简单地添加到父节点。在此程序中,在添加之前,我必须检查有多少子项,出于其他原因。
SelectedItem.Children.Add()
是有效的。 - Eric after dark