Shift + F10打开错误的上下文菜单 [英] Shift+F10 open wrong context menu
问题描述
我有一个简单的树状视图.每个树项都有基于您在树中的位置的自定义上下文菜单.这些项目然后绑定到命令.右键单击将为每个树项目打开正确的上下文菜单.但是,当我使用键盘快捷键或Shift + F10时,只能看到顶部树项目的上下文菜单.无论我在树中的哪个位置单击,都会显示顶级树项目的上下文菜单. < I have a simple treeview. Each tree item has custom context menu's based on where you are in the tree. These items are then bound to commmands. The right-mouse click will bring up the correct context menu for each tree item. However, when I use the keyboard shortcut or Shift+F10, I only see the top tree-item's context menu. No matter where I click in the tree, the top level tree item's context menu is shown. < Looks like an issue with keyboard focus. Invoking context menu with keyboard requires that the element has keyboard focus. You are always getting the top items context menu because the keyboard focus is with the top level item. When you right click with mouse, the item gets selected, but doesn't get keyboard focus. Looks like an issue with keyboard focus. Invoking context menu with keyboard requires that the element has keyboard focus. You are always getting the top items context menu because the keyboard focus is with the top level item. When you right click with mouse, the item gets selected, but doesn't get keyboard focus. 这篇关于Shift + F10打开错误的上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
关于发生什么的任何想法吗?
这是xaml:
Any ideas as to what is going on?
here is the xaml:
推荐答案
I experimented by setting Focusable="True" on the TextBlocks in both HierarchicalDataTemplates. This works - I get the context menu of corresponding tree view item. But something is odd with navigation, you need to press down arrow set keyboard focus on an item. I suggest you go though Focus Overview (http://msdn.microsoft.com/en-us/library/aa969768.aspx) and experiment with logical and keyboard focus events.
I experimented by setting Focusable="True" on the TextBlocks in both HierarchicalDataTemplates. This works - I get the context menu of corresponding tree view item. But something is odd with navigation, you need to press down arrow set keyboard focus on an item. I suggest you go though Focus Overview (http://msdn.microsoft.com/en-us/library/aa969768.aspx) and experiment with logical and keyboard focus events.