开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜