I have a TreeView that is bound to a dataset which is having parent child relation. How i will get seleted TreeViewItem from the TreeView? Please help me. My code is below.
This works for trees whose data source is bound via a HierarchicalDataTemplate
Handle TreeViewItem.Selected
And set the TreeViewItem as the Tag.
private void TreeViewItem_OnItemSelected(object sender, RoutedEventArgs e)
{
mTreeView.Tag = e.OriginalSource;
}
Which you can retrieve later
TreeViewItem tvi = mTreeView.Tag as TreeViewItem;