tags:

views:

381

answers:

3

I have a scenario where I am displaying a popup on my control. I am able to do this using PlacementTarget, Position, etc.

My problem is when I resize the window and move it to somewhere else in the desktop, the popup remains stationary meaning it doesn't move with the control set as PlacementTarget. I was able to hide it in case of other window getting focus. But not able to attach it with my control.

How can I solve this problem? Is there any other such control available?

A: 

I don't think you'll get the behavior you want without deriving from Popup and doing some handling.

If you have the PlacementTarget then you can get the Window that it should follow, right? So when the Popup is showing watch the Window containing the PlacementTarget for movement and adjust the popup accordingly. Popup derives from Window so it should have a Left and Top property.

Steven
+1  A: 

If you look at all WPF controls from MS, their Popup in the ControlTemplate is automatically closed when you click somewhere outside the Control. (e.g. ComboBox)

It's this property responsible for that: StaysOpen="False"

The easiest hack is to define a Window which will look like a Popup and bind its position Properties to your control with a Converter adding some pixels to it.

PaN1C_Showt1Me
A: 

It is not a perfect solution, but if you have an event to work with, in this case Resize or LocationChanged, you can coax the popup to move by changing one of its offsets and changing it back.

Something like this:

popup.HorizontalOffset += 0.01

popup.HorizontalOffset -= 0.01

John Christman