Absolute position

Oct 19, 2009 at 2:04 AM
Edited Oct 19, 2009 at 2:12 AM

Hello,

Thank you for the great piece of software!

My question is in regards to the activation of a drop target upon its entry.  This seems to only be possible when the top, left position of the drag source has entered the drop target.  In the source, I believe this is happening here:

 

 

 if (offsetMine.X > item.internalOffset.X && offsetMine.X < item.internalOffset.X + item.ActualWidth)
{
// X-coordinates are ok
if (offsetMine.Y > item.internalOffset.Y && offsetMine.Y < item.internalOffset.Y + item.ActualHeight)
{
// Y-coordinates are ok
// fire event on droptarget
item.TriggerDropTargetEntered(this);
isInDropTarget = true;
break;
}
else
{
// X ok, Y not: not hovering anymore
item.TriggerDropTargetLeft(this);
}
}
else
{
// X not ok
item.TriggerDropTargetLeft(this);
}

 

 

I'd like to request that when the mouse position enter the drop target events are fired?

The problem occurs when the drop target is right-aligned to the edge of a silverlight application.  If the drag source is wider than the drop target, the mouse stops at the edge making it difficult to completed the drop.  Most users will not know to select their drag source at the top left corner.

 

Thanks!

 

ISZ

Oct 19, 2009 at 2:22 AM

For the time being, I modified the source to use the center of the drag source.  This helps, but the mouse position might be better.

            // get my absolute position
            Point offsetMine = 
                this.MainDraggableControl
                .TransformToVisual(Application.Current.RootVisual as UIElement)
                .Transform(new Point(0, 0));

            offsetMine.X = offsetMine.X + (this.MainDraggableControl.ActualWidth / 2);
            offsetMine.Y = offsetMine.Y + (this.MainDraggableControl.ActualHeight / 2);

Oct 22, 2009 at 1:54 AM
Edited Oct 22, 2009 at 1:57 AM

Ok, I now have the target activated with respect to the mouse location, rather than the drag source location.  This was done by passing in the DragBar mouse position, and passing that as a point.

 

 

        /// 
/// Method to check if "I" am in one of my droptargets
///
///
/// <param name="position" />The current mouse position relative the the DragBar.
private void CheckIfIAmInDropTarget(Point position)
{
// get my absolute position
Point offsetMine =
this.MainDraggableControl
.TransformToVisual(Application.Current.RootVisual as UIElement)
.Transform(position);

isInDropTarget = false;

 

Rather than a new Point(0, 0), I passed the position from the method argument to get the actual position relative to the root layout container... .Transform(position);

If you think this is a better solution, let me know, otherwise, perhaps an enumeration that lets the user choose what point is used to perform the activation, ie. TopLeft, TopRight, BottomLeft, BottomRight, Center, MousePosition.

Sep 20, 2011 at 4:46 AM

Thanks for posting, you put me on the right track for fixing this issue.  With the current lastest source code, here's the changes I had to made to ensure the mouse position is used rather than the top-left coordinates of the control being dragged, in DragSource.cs:

1.  In DragBar_MouseLeftButtonUp():

Replace:

             DropTarget dropTarget = GetCorrectDropTarget();

With:

            DropTarget dropTarget = GetCorrectDropTarget(e.GetPosition(this.MainDraggableControl));

2.  Change GetCorrectDropTarget() to take a parameter of type Point, and replace (new Point(0,0)) with that argument.

3.  In DragBar_MouseMove():

Replace:

                CheckIfIAmInDropTarget();

With:

                CheckIfIAmInDropTarget(e.GetPosition(this.MainDraggableControl));

4.  Perform the changes as posted by isz_plex above in CheckIfIAmInDropTarget().