I understand that programming in C # with WPF is different from traditional C # procedures, so most online materials do not indicate what I need.
I have a TreeView control in my WPF window, and I have parent nodes and child nodes. I would like to save them in a list of type Node (id, name, parent).

I got the name of the selected / node element using this:
private void TreeViewItem_OnItemSelected(object sender, RoutedEventArgs e) { TreeViewItem item = treeView.SelectedItem as TreeViewItem; nameTxt.Text = item.Header.ToString(); }
And I tried to get the Node child's parent just before that using this:
TreeViewItem item = treeView.SelectedItem as TreeViewItem; nameTxt.Text = item.Parent.ToString();
However, this returns the root parent (A) instead of the parent parent (which is 2).
What changes should be made to get the parent parent instead of the root parent? :)
EDIT: here is XAML
<TreeView Name="treeView" HorizontalAlignment="Left" Height="564" Margin="10,68,0,0" VerticalAlignment="Top" Width="363"> <TreeViewItem TreeViewItem.Selected="TreeViewItem_OnItemSelected" Header="A" IsExpanded="True" Height="554" FontSize="18"> <TreeViewItem Header="1" /> <TreeViewItem Header="2" /> </TreeViewItem> </TreeView>
source share