I am using HierarchicalDataTemplate to form the tree. I am doing the following things: 1. Select a folder and click on "Add Folder" button. 2. A new folder under a selected folder should be shown. The ViewModel is updated correctly such that it has a Folder under the selected folder element and the same is updated in the TreeView.
My concern is how do I get the TreeViewItem of the added folder. I have the reference to the newly added folder but don't know how to get the TreeViewItem of the same. Below is the sample code that adds the folder
ElementFolder folder = ViewModel.AddFolder(selectedFolder, "NewFolder");
Here, folder is the reference to the new folder added of type ElementFolder. The ItemsSource of the HierarchicalDataTemplate is ElementFolder.
Please help. I am stuck. Read many posts but none came to my rescue. Please help !! I tried the ideas mentioned in this link but it did not help : How to get TreeViewItem from HierarchicalDataTemplate item?