Saggio
Saggio

Reputation: 2274

WPF Thumb DragDelta moving across monitors

I have a Popup control that I added a thumb to so I can drag it around the screen. The thumb's DragDelta event was overloaded with this:

private static void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
    {
        Thumb thumb = (Thumb)sender;
        Popup popup = thumb.Tag as Popup;

        if (popup != null)
        {
            popup.HorizontalOffset += e.HorizontalChange;
            popup.VerticalOffset += e.VerticalChange;
        }
    }

The Dragging works perfectly (I used the Dragging example from here: http://www.codeproject.com/Articles/43636/WPF-A-search), except for when the popup reaches the end of the monitor and crosses over to the other (dual monitor setup). For instance if I have the popup open on the Left monitor and start dragging it right, when the right border of it touches the edge of the monitor it's movement is erratic and starts moving all around until I move further right and it displays on the other monitor.

I debugged through this scenario, and this is a numerical example of basically what happens:

At edge of screen:
HorizontalOffset = 600
HorizontalChange = 1

Move Right:
HorizontalOffset = 601
HorizontalChange = -800

HorizontalOffset = -199
HorizontalChange = 401

HorizontalOffset = 200
HorizontalChange = -150

Which gives this weird strobe effect of the popup while it moves to the other monitor; Is there something I need to do to get it to transition smoothly across monitors?

Upvotes: 4

Views: 1794

Answers (1)

Saggio
Saggio

Reputation: 2274

I still haven't figured out how to un-bind pop-ups to a screen, but I was able to accomplish what I needed by using the Window control instead. I made WindowStyle.None so there was no border and overloaded the MouseLeftButtonDown event with a delegate to the DragMove() method so they can be dragged around the screen. This allowed me to have very similar look and feel as the pop-ups, but able to drag it around the screen with no flicker.

Upvotes: 3

Related Questions