Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have a couple of choices on how to achieve your goal. Either you can create a <code>Command</code> that opens the <code>ContextMenu</code>, then add a <code>KeyBinding</code> with the command and a <code>KeyGesture</code> of <code>ALT + CTRL</code> to the <code>InputBindings</code> of your main window.</p> <p>You can find out more about the <code>KeyBinding</code> class from the <a href="http://msdn.microsoft.com/en-us/library/system.windows.input.keybinding.aspx" rel="nofollow">KeyBinding Class</a> page and the <code>KeyGesture</code> class from the <a href="http://msdn.microsoft.com/en-us/library/system.windows.input.keygesture.aspx" rel="nofollow">KeyGesture Class</a> page at MSDN.</p> <p>The other option is to add a handler for the <code>PreviewMouseDown</code> (or similar) event and monitor whether the <code>ALT</code> and <code>CTRL</code> keys are being pressed, then programmatically launch the <code>ContextMenu</code> control if they are:</p> <pre><code>public void ListBox_PreviewKeyDown(object sender, KeyEventArgs e) { if ((e.KeyboardDevice.Modifiers &amp; ModifierKeys.Alt) == ModifierKeys.Alt &amp;&amp; (e.KeyboardDevice.Modifiers &amp; ModifierKeys.Control) == ModifierKeys.Control) { // Open ContextMenu } } </code></pre> <p>Now all that is left is to open the <code>ContextMenu</code> from code:</p> <pre><code>if (element.ContextMenu != null ) { element.ContextMenu.PlacementTarget = element; element.ContextMenu.IsOpen = true; } </code></pre> <p>If the <code>ContextMenu</code> is not placed correctly, you can set the placement using the <code>ContextMenu.HorizontalOffset</code> and <code>ContextMenu.HorizontalOffset</code> properties.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload