Shift + F10打开错误的上下文菜单 [英] Shift+F10 open wrong context menu

查看:69
本文介绍了Shift + F10打开错误的上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的树状视图.每个树项都有基于您在树中的位置的自定义上下文菜单.这些项目然后绑定到命令.右键单击将为每个树项目打开正确的上下文菜单.但是,当我使用键盘快捷键或Shift + F10时,只能看到顶部树项目的上下文菜单.无论我在树中的哪个位置单击,都会显示顶级树项目的上下文菜单.

关于发生什么的任何想法吗?

这是xaml:

<

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.

Any ideas as to what is going on?

here is the xaml:

<

 

 

 

 

 

 

 

 

推荐答案

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.

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.

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.

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.


这篇关于Shift + F10打开错误的上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆