我对 WPF 中的“ContextMenu”有疑问。有没有办法只有在执行“Shift-Right-Click”时才会弹出上下文菜单?我一直在到处寻找这个。ContextMenu 似乎只能在“右键单击”时弹出。
有人有想法么 ??
我对 WPF 中的“ContextMenu”有疑问。有没有办法只有在执行“Shift-Right-Click”时才会弹出上下文菜单?我一直在到处寻找这个。ContextMenu 似乎只能在“右键单击”时弹出。
有人有想法么 ??
试试这个……你的 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));
}