Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display a Popup above mouse location?
    text
    copied!<p>I have a <code>DataGrid</code> control in my application in which I added a custom-defined <code>Popup</code> for some actions. The basic thing is: I have a matrix of <code>double</code> numbers displayed in a <code>DataGrid</code>. Right clicking on selected cells will make a popup appear, in which the user can type a value then press enter to shift the values selected (all of the values selected will be incremented with the value entered)</p> <p>Here is the current behavior:</p> <p><img src="https://i.stack.imgur.com/BBKEU.png" alt="Shift popup"></p> <p>And the XAML code for the popup:</p> <pre><code>&lt;Style x:Key="ShiftPopupStyle" TargetType="{x:Type Popup}"&gt; &lt;Setter Property="IsOpen" Value="False" /&gt; &lt;Setter Property="StaysOpen" Value="False" /&gt; &lt;Setter Property="AllowsTransparency" Value="True" /&gt; &lt;Setter Property="PopupAnimation" Value="Fade" /&gt; &lt;Setter Property="Placement" Value="Mouse" /&gt; &lt;Setter Property="Child"&gt; &lt;Setter.Value&gt; &lt;Border BorderBrush="Navy" Background="AliceBlue" BorderThickness="1" CornerRadius="2"&gt; &lt;StackPanel Orientation="Horizontal" Margin="5"&gt; &lt;TextBox Text="{Binding ShiftValue, UpdateSourceTrigger=PropertyChanged}" Width="30" Margin="4" &gt; &lt;TextBox.InputBindings&gt; &lt;KeyBinding Command="{Binding ShiftCommand}" Key="Enter" /&gt; &lt;/TextBox.InputBindings&gt; &lt;/TextBox&gt; &lt;Button Content="Shift" Margin="0,4,0,4" Command="{Binding ShiftCommand}"/&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>And here is how I open the <code>Popup</code>, this method is located in my custom <code>DataGrid</code> (I use a custom <code>DataGrid</code> able to display values from a 2D Array):</p> <pre><code>protected override void OnMouseRightButtonUp(System.Windows.Input.MouseButtonEventArgs e) { if (!this.IsReadOnly) { this.shiftPopup.IsOpen = true; } base.OnMouseRightButtonUp(e); } </code></pre> <p>Now, I need to add a <code>ContextMenu</code> to my <code>DataGrid</code>. When I try to add a <code>ContextMenu</code> directly on the <code>DataGrid</code>, I can see it before the grid is initialized, but afterwards, only the <code>Popup</code> shows up. No <code>ContextMenu</code> at all. I was expecting them to be at the same location, but the <code>ContextMenu</code> just won't appear.</p> <p>Ideally what I'd need is an Office-like <code>ContextMenu</code>:</p> <p><img src="https://i.stack.imgur.com/Rr3vX.png" alt="Office popup"></p> <p>In which my shift Popup would appear above the mouse pointer, and my <code>ContextMenu</code> at the usual position.</p> <p>If needed, I wouldn't care having a fixed layout (layout above/contextmenu under, whatever the mouse position is).</p> <p>Would you have any idea on how to do so?</p> <p>Alternatively, I was thinking about including the <code>Popup</code> content in the contextMenu, hoping it won't end up being ugly.</p> <p>Thanks for your help!</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