我有一个关于WPF中的“ContextMenu”的问题。是否有一种方法只有在执行“Shift-Right-Click”时才弹出上下文菜单?我已经到处寻找了这个答案。似乎只有在进行“右键单击”时,ContextMenu才能弹出。你们有什么想法吗?
<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));
}