i setup a little test app. There is only a stackpanel with some buttons and a black rectangle...
Its possible to drag and drop the rectangle into the stackpanel!
Now i would like to provide feedback to the user! The ui element in this case the black rec should be placed near the cursor...
I don't have a idea todo that... please help me with some nice code! thanks :)
private Point startPoint;
rect.PreviewMouseLeftButtonDown += (s, e) =>
startPoint = e.GetPosition(null);
rect.MouseMove += (s, e) =>
Point mousePos = e.GetPosition(null);
Vector diff = startPoint - mousePos;
if (e.LeftButton == MouseButtonState.Pressed &&
Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance &&
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
Rectangle r = s as Rectangle;
DataObject dragData = new DataObject("rect", r);
DragDrop.DoDragDrop(r, dragData, DragDropEffects.Move);
stack.AllowDrop = true;
stack.DragEnter += (s, e) =>
if (!e.Data.GetDataPresent("rect") || s == e
View Complete Post