我对WPF中的“ContextMenu”有疑问。有没有办法只在执行“Shift-Right-Click”时弹出上下文菜单? 我一直在寻找这个地方。只有在进行“右键单击”时,才能弹出ContextMenu。
任何人都有任何想法??
答案 0 :(得分:6)
试试这个......你的XAML上下文菜单属性应该如下所示......
<ElementToWhichContextMenuIsAttached ContextMenu="{StaticResource MyContextMenu}"
ContextMenuOpening="MyContextMenuOpening"/>
你的代码背后会是这样的。
/// <summary>
/// This will suppress the context menu if the shift key is not pressed
/// </summary>
private void MyContextMenuOpening(object sender, ContextMenuEventArgs e)
{
// Show context menu as handled if no key is down.
e.Handled = !(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift));
}