DropTarget_DragSourceDropped Mouse coordinates

Nov 5, 2009 at 7:58 PM


  I need to know the mouse coords where the user has dropped the item, I have checked the DragSourceProperty but didn't get any property, also played with the MouseEvent but is launched after the drop event.



Nov 7, 2009 at 8:27 PM


  Just taking a look to your code, maybe I'm missing something, but I think it would be a good idea to add a member variable to hold the global mouse position where you have dropped and object.

  You could update it in this event from the DragSource (maybe on mouse move could be as well a good idea):

<font size="2">



void DragBar_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

  By doing this we can retrieve the exact coordinate where the user has dropped the control (in a diagram like application is quite important to know this, tried with MouseMove on the parent container but is launched after the releasecapture).

  Will try to hook to mousemove / leftbutton up of the Drag Source to avoid modifying your root code (will try to inherit and create a member variable for that global coords).



Nov 7, 2009 at 9:26 PM

Implemented a workaounrd (extending your class), is there any cleaner solution?

Class Extension:

    public class DragSourceExt : DragSource
        public MouseButtonEventArgs DropMouseEventArgs { get; set; }

        public DragSourceExt()
            this.MouseLeftButtonUp += new MouseButtonEventHandler(DragSourceExt_MouseLeftButtonUp);

        /// <summary>
        /// Just before dropping capture mouse event args
        /// The drop event will be able to access this property (dropMouseEventArgs) and
        /// map them to the container where is dropped (exact X,Y drop).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void DragSourceExt_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            DropMouseEventArgs = e;



XAML: Use the DragSourceExt instead of DragSource

Drop Event:


        private void DropTarget_DragSourceDropped(object sender, DropEventArgs args)
            Point dropPoint = new Point(0, 0);
            dropPoint = dragSourceExt.DropMouseEventArgs.GetPosition(CanvasDropTarget);

Nov 22, 2009 at 10:46 AM



thanks for this idea - I'll certainly keep this in mind for the next version!



Dec 10, 2009 at 3:18 PM

I agree to this, having the x/y point on MouseLeftButtonUp would be perfect to position Elements for example within a Canvas