Problem explained short:
Node 1
Child x
Child Y
Node 2
Child z
When dealing with TreeView type, when selecting a parent node, the SelectedItem property returns an object of type TreeViewItem and the following works properly
TreeViewItem parentNode = (TreeViewItem) treeView.SelectedItem;
This while, this property return a String when a value of a node is selected which means in that case the following will be true:
Boolean valueType = treeView.SelectedItem is String; --> True
Accordingly, we cannot cast the object to the TreeViewItem anymore.
Assuming you got the following
IEnumerable<IGrouping<String, Childs>> treeModel;
And you want to know to which node the child belongs, how would you obtain the parent node element from the TreeView.