Josh Smith

What is the recommended way of getting the mouse cursor position during a drag-and-drop operation Using Mouse.GetPosition() or DragEventArgs.GetPosition() always returns some incorrect value. I just noticed that Dan Crevier circumvented this issue by Pinvoking into userland (http://blogs.msdn.com/llobo/archive/2006/09/06/Scrolling-Scrollviewer-on-Mouse-Drag-at-the-boundaries.aspx) but I would prefer to avoid that. Is there a reason why the WPF APIs for retrieving the mouse position do not work properly during drag-and-drop operations




Re: Windows Presentation Foundation (WPF) Mouse Position During Drag-And-Drop

Josh Smith

(bump) Does anyone know why this is so




Re: Windows Presentation Foundation (WPF) Mouse Position During Drag-And-Drop

Josh Smith

(bump bump) Come on, folks. Noone at MS can shed any light on this I've seen several demos online where MS devs work around the issue, always in different ways. What's the best workaround Why do I need to work around this in the first place Is this going to be fixed in v2




Re: Windows Presentation Foundation (WPF) Mouse Position During Drag-And-Drop

LesterLobo - MSFT

marcelo has some drag drop code (http://blogs.msdn.com/marcelolr/archive/2006/03/03/543301.aspx) using Mouse.GetPosition which gives accurate results. Pavan Podila has also written some drag drop code which uses the same.



Re: Windows Presentation Foundation (WPF) Mouse Position During Drag-And-Drop

Josh Smith

Hmmm... I don't know. I've definitely encountered issues with it. Hopefully it's just a mistake on my part, but I'll see if I can create a little demo project to reproduce the issue. I'm still wondering why so many samples I've seen use PInvoke to get mouse coords during drag-drop operations.






Re: Windows Presentation Foundation (WPF) Mouse Position During Drag-And-Drop

Ifeanyi Echeruo

Mouse.GetPostion(element) gets the mouse Coordinates *relative* to an element. Most people assume mouse coordinates are absolute and write buggy mouse logic.

For instance code that drags an element probably shouldnt call Mouse.GetPosition() on that element or its subtree, it should use a stationary visual like the elements parent instead.

--Ifeanyi Echeruo [MSFT]






Re: Windows Presentation Foundation (WPF) Mouse Position During Drag-And-Drop

Sam

I've also encoutered issues. I was adapting Dan Crevier's DragDropScrollViewer (http://blogs.msdn.com/llobo/attachment/743461.ashx), and I thought I could do away with his MouseUtilities class by using Mouse.GetPosition.. Sometimes it worked, but often it didn't, and I had to go back to his workaround.



Re: Windows Presentation Foundation (WPF) Mouse Position During Drag-And-Drop

Josh Smith

Sam,

I've looked for a workaround for a long time now, but there's no way around it. Crevier's use of PInvoke is necessary.