簡體   English   中英

WPF ContextMenu使用(Shift-Right-Click)

[英]WPF ContextMenu using (Shift-Right-Click)

我對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));
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM