![](/img/trans.png)
[英]Disable Right click and enable left click for contextmenu in WPF using MVVM
[英]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.