This is a migrated thread and some comments may be shown as answers.

Drag and drop from listbox to canvas that has a transform

4 Answers 74 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 22 Sep 2010, 02:14 AM
I have a canvas inside of a scrollviewer that allows me to zoom in and out of my canvas. I am trying to drag items from a listbox onto the canvas. I've been using some examples that I found online and in this forum. As longer as the user doesnt zoom, everything works as expected. However once the user zooms in or out, the items being dragged onto the canvas are randomly placed. Here is the pertinent code from my OnDropInfo method

Point desiredPosition = new Point();
Point currentDragPoint = e.Options.CurrentDragPoint;
Point canvasPosition = this.TransformToVisual(null).Transform(new Point());
                 
desiredPosition.X = currentDragPoint.X - canvasPosition.X;
desiredPosition.Y = currentDragPoint.Y - canvasPosition.Y;


How can I change this to make zooming work?

4 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 22 Sep 2010, 01:05 PM
Hello David,

Could you please send some additional information about the way you have implemented the zoom functionality. Are you using the browser zoom or some kind of scale transformation?

Sincerely yours,
Tsvyatko
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
David
Top achievements
Rank 1
answered on 22 Sep 2010, 03:45 PM
I am zooming using a scale transform


ZoomTransform = new ScaleTransform();
 
ZoomTransform.ScaleX *= zoom;
ZoomTransform.ScaleY *= zoom;
this.RenderTransform = ZoomTransform;
0
Accepted
Tsvyatko
Telerik team
answered on 23 Sep 2010, 01:34 PM
Hi David,

I have prepared sample application showing how to handle this scenario. Please have a look and let know if this work for you.

Greetings,
Tsvyatko
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
David
Top achievements
Rank 1
answered on 23 Sep 2010, 04:05 PM
Works great!

I think the only issue is that:
 
desiredPosition.X = (currentDragPoint.X - canvasPosition.X) / scaleTransform.ScaleY;

Should be:

desiredPosition.X = (currentDragPoint.X - canvasPosition.X) / scaleTransform.ScaleX;




thanks so much!

Tags
DragAndDrop
Asked by
David
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
David
Top achievements
Rank 1
Share this question
or