Question

I'm trying to write an event handler that fires every time a node in a TreeView gets the focus. The problem I'm running into is that the event handler fires on the TreeViewItem (node) that I click on with the mouse, and then it continues to bubble up the control tree, even though I've set e.Handled = true on the RoutedEventArgs provided to the handler. Does anybody have an idea what the problem could be ? I've double checked my code and I can see no reason why this should be happening.

Was it helpful?

Solution

Are you using TreeView.GotFocus when you really want TreeViewItem.Selected?

    <TreeView TreeViewItem.Selected="treeView1_Selected"  />

If you really want focus, use TreeViewItem.Focus instead so that items are targeted instead of the whole tree.

    <TreeView TreeViewItem.GotFocus="treeView1_GotFocus"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top