Hi All,
In my WPF application I have a treeview which is loaded with certain collection. At the top of this tree view control i have a listbox which stores the same items as in the tree view whenever the tree view items are made favorites. I am trying to focus the treeview item whenever there is a selection made in the listbox. Though the relevant item is getting selected in the tree view whenever i select an item in the listbox, but I am not able to focus the treeview item. Since the tree view is huge, there is a vertical scrollbar and if the item selected in the listbox falls in the non visible part of the tree view, I want the scrollbar to be set so that the treeview item gets selected. Though I am calling Focus explicitly on the selected treeviewitem, I am unable to see the item in the visible pane of the treeview.
Could anyone please help me in achieving the above behavior?
Here is the code I am using from Josh Smith's article on attachedbehaviors:
`static void OnTreeViewItemSelected(object sender, RoutedEventArgs e)
{
if (!Object.ReferenceEquals(sender, e.OriginalSource)) return;
TreeViewItem item = e.OriginalSource as TreeViewItem;
if (item != null) item.BringIntoView();
}
`
Thanks!