haithambradai / gong-wpf-dragdrop

Automatically exported from code.google.com/p/gong-wpf-dragdrop
0 stars 0 forks source link

About DragInfo.DragStartPosition - e.GetPosition(null) is misleading when using with Context menu #35

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I would begin with that, this is a wonderful framework for Drag and Drop in 
wpf. 
Ok, with that said, there was a small issue that I had been facing. I just 
wanted to report that and also how I resolved it? I was trying this framework 
with a ListView. My listview control is my DragSource(=True). Incidently, the 
listview also has its context menu. Now the problem arises when I right-click 
on an item and then (just to close the context menu) click anywhere (sometimes 
on one of the items) on the listview. Now when I would click on one of the 
items, it sets System.Windows.DragDrop.DoDragDrop(,,,), in the 
DragSource_PreviewMouseMove event handler, even though I had just clicked the 
left button (not dragged it). It would have been fine otherwise, but in this 
case it does not fire the PreviewMouseLeftButtonUp event, with the result that 
my Mouse pointer stops taking any input. I am not able to click on any other 
button on the window untill I minimize and then maximize the window. Now here 
is the list of events that could be reason of the problem;
1.I right click on an item in listview to bring-up the Context menu.
2.I donot click on the Context menu item and instead click on some listviewitem 
again to close the context menu
-here, first PreviewMouseLeftButtonDown is called which is handled by 
DragSource_PreviewMouseLeftButtonDown
-inside this handler this code, "mDragInfo = new DragInfo(sender, e);" creates 
mDragInfo
-inside the ctor of mDragInfo, this code, "DragStartPosition = 
e.GetPosition(null);" sets the DragStartPosition, BUT RELATIVE TO MY CONTEXT 
MENU
-then, PreviewMouseMove is called which is handled by 
DragSource_PreviewMouseMove
-here, this code, "Point position = e.GetPosition(null);" takes the position 
again, BUT THIS TIME RELATIVE TO MY LISTVIEW
-and when it compares the two positions in the code below, it evaluates to True;
if (Math.Abs(position.X - dragStart.X) > 
SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(position.Y - dragStart.Y) > 
SystemParameters.MinimumVerticalDragDistance)
-and this leads to setting the System.Windows.DragDrop.DoDragDrop(,,,)
which wouldn't have otherwise happened if it would be a simple mouse-click on a 
list view

To resolve it, I simply took "sender" as argument for the two e.GetPosition() 
statements (one in the ctor of DragInfo and the other in 
DragSource_PreviewMouseMove event handler). Since, in my case the sender in 
context of both the statements was the same listview, so I could get it right.

Original issue reported on code.google.com by man...@drake.in on 27 Apr 2011 at 6:50

GoogleCodeExporter commented 9 years ago
See my fix for issue 22.

Original comment by DWick...@gmail.com on 6 Jun 2011 at 4:17