使用(Shift-右键单击)的 WPF 上下文菜单

发布于 2024-10-24 20:23:14 字数 113 浏览 5 评论 0原文

我对 WPF 中的“ContextMenu”有疑问。有没有办法仅在执行“Shift-右键单击”时弹出上下文菜单? 我一直在到处寻找这个。上下文菜单似乎只能在“右键单击”时弹出。

有人有什么想法吗?

I have a question with the "ContextMenu" in WPF. Is there a way to have the context menu pop up only if a "Shift-Right-Click" was performed??
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.

Anyone have any idea's ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜司空 2024-10-31 20:23:14

试试这个...您的 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));
    }

Try this.... your XAML context menu properties should look like this...

<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));
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文