I have a question w开发者_如何学Cith 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 ??
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));
}
精彩评论