I have the same problem as a previous question on this forum:
I have a TreeView which uses a HierarchicalDataTemplate to bind its data. I need to get the TreeViewItem from the selected item, which is my own class.
I have tried the solution given in the previous thread as well as modified versions of it. Nothing works. myTreeView.Items.CurrentPosition returns -1. If I check inside Items I can only see my 2 root items. I have several levels of items.
myTreeView.ItemContainerGenerator.ContainerFromObject(myTreeView.SelectedItem) doesn't work either, it returns null. myTreeView.ItemContainerGenerator.ContainerFromObject(myTreeView.Items.CurrentObject(myTreeView.Items.CurrentItem) returns null.