[英]WPF ContextMenu using (Shift-Right-Click)
I have a question with the "ContextMenu" in WPF. 我对WPF中的“ContextMenu”有疑问。 Is there a way to have the context menu pop up only if a "Shift-Right-Click" was performed??
有没有办法只在执行“Shift-Right-Click”时弹出上下文菜单? I have been looking all over the place for this.
我一直在寻找这个地方。 The ContextMenu seems to only be able to pop up when a "right-click" is made.
在进行“右键单击”时,ContextMenu似乎只能弹出。
Anyone have any idea's ?? 有人有主意吗 ??
Try this.... your XAML context menu properties should look like this... 试试这个....你的XAML上下文菜单属性应该如下所示......
<ElementToWhichContextMenuIsAttached ContextMenu="{StaticResource MyContextMenu}"
ContextMenuOpening="MyContextMenuOpening"/>
And your code behind will look like this. 你的代码背后会是这样的。
/// <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));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.