0
votes

The behavior I want is this: when the popup is opened, it should be opened so that the mouse point is within a 5 px margin of the edge of the popup. My current code is this:

productCategoryPopup.Placement = PlacementMode.MousePoint; productCategoryPopup.VerticalOffset = -5; productCategoryPopup.HorizontalOffset = -5;

and

<Popup x:Name="productCategoryPopup" IsOpen="False" StaysOpen="False" AllowsTransparency="True">...</popup>

This works as long as the popup isn't automatically displaced, which it is in the case where the content is too long to fit on the screen, if the top-left corner is at the mousepoint. So my offset, which was added to ensure that the mouse if inside, with a margin, now makes the popup open outside. This in turn immediately closes the popup, which I assume is due to the fact that my mouseup lands outside the popup.

To clarify, what happens when i open a popup near the bottom of the screen is that the popup opens such that it's bottom left corner is 5 pixels above (-5) and to the left of the mousepoint, it then closes if I release the mouse button.

What is the best way of achieving the above stated behavior?

1

1 Answers

1
votes

I believe by setting the property PlacementRectangle will help to achieve this behavior.

 PlacementRectangle="-100,0,30,30"

XAML

 <Popup IsOpen="{Binding OpenPopUp}" 
                   HorizontalAlignment="Center" 
                   VerticalAlignment="Center" 
                   ClipToBounds="True"
                   PlacementRectangle="-100,0,30,30"
                   AllowsTransparency="True"
                   PopupAnimation="Scroll">
        ....
</Popup>

Output

enter image description here

In my case its having less controls but, as you needed its having a margin from the button 'Add User' which opens the popup. And popup stays until i click cancel.