views:

1891

answers:

4

We are using popup windows in a Silverlight 2 application; these can be moved in the standard way by clicking on the title bar and dragging. If the title bar is dragged out of site behind the browser chrome, the window can no longer be moved.

We have users that consider this problematic and I was wondering if there might be some other way to allow the window to be moved when they have got it stuck behind the chrome.

Or perhaps a way to prevent any part of the popup from going out of the window would be better.

A: 

The best way to deal with this would be to prevent the user from dragging it outside of the browser window. To do this you could get the Width and Height of the Silverlight host control. Once you have that information you can check the location of the window as the user drags it and not let them go beyond the bounds of the window.

Bryant
+1  A: 

After digging a bit I discovered that there is no standard dragging mechanism for pop-ups but that a colleague had implemented it. It was easy to expand the code to constrain the pop-up to the host window. It behaves a bit strangely though. Slow and smooth dragging allows the popup to move right up to the edge of the host window but fast erratic dragging causes it to be stopped before quite reaching the edge. Still trying to figure out why that is.

Steve Crane
+2  A: 

You mouse movements are reported at discrete time intervals. That is, the faster you move the mouse, the farther apart the reported mouse positions are. Dragging the mouse fast from inside to outside the window can report a position well inside the window (PointA), while the next report will be well outside the window (PointB). If you use the CaptureMouse call while dragging you can still receive mouse position reports while the pointer is outside the host window. When you discover you have moved beyond the window you can assume the mouse is at the edge of the window. That is, if you were to draw an imaginary line from PointA to PointB, you can assume your last point is where that line crossed the window border. If you do not use MouseCapture, or you are using a windowless plugin, I don't think you will see mouse events when dragging outside the window. In that case, estimating the position where the mouse crossed the window border is more difficult.

ptoinson
A: 

could it be because the Mouse_Leave event is firing??

brad