Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
punker76 opened this issue Feb 18, 2013 · 2 comments

Comments

@punker76
Copy link
Owner

Original author: man...@drake.in (April 27, 2011 06:50:20)

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: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=35

@punker76
Copy link
Owner Author

From DWick...@gmail.com on June 06, 2011 16:17:43
See my fix for issue #22.

@punker76
Copy link
Owner Author

fixed in 0.1.3.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant