我对 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));
}
关于WPF ContextMenu 使用 (Shift-Right-Click),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5383800/