开发者

Preventing WPF TreeView's GotFocus event from bubbling up the tree

开发者 https://www.devze.com 2022-12-13 01:11 出处:网络
I\'m trying to write an event h开发者_开发技巧andler 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)

I'm trying to write an event h开发者_开发技巧andler 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.


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"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消