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

Dropping into Viewbox

3 Answers 64 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 21 Oct 2010, 02:32 PM
I have my drop and drag working to drop object into Canvas wrapped in a ViewBox.    The viewbox is scaling the canvas so that it displays the fill object on the screen.

My problem is that the coordinates within the canvas are no longer the same as the screen coordinates.  I'm currently using below code from examples -

Camera1Canvas.Children.Add(userControl);
// Determine the drop point for the new UserControl.
Point canvasPosition = Camera1Canvas.TransformToVisual(null).Transform(new Point(0, 0));
var userControlDesiredPosition = new Point
           {
              X = e.Options.CurrentDragPoint.X - canvasPosition.X,
              Y = e.Options.CurrentDragPoint.Y - canvasPosition.Y
            };
// e.Options.CurrentDragPoint returns the absolute mouse position,
// that is why we have to transform the host canvas and subtract its position from the absolute mouse position.
userControl.SetValue(Canvas.LeftProperty, canvasPosition1.X);
userControl.SetValue(Canvas.TopProperty, canvasPosition1.Y);
userControl.SetValue(Canvas.ZIndexProperty, Camera1Canvas.Children.Count);
userControl.TabIndex = Camera1Canvas.Children.Count;

And this code works just fine if I'm positioning object to the screen coordinates.  I need to understand how to map those coordinates so that object is placed in the correct location inside the canvas inside of the viewbox.

Tom

3 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 21 Oct 2010, 03:19 PM
Hi Tom,

Please, have a look at this thread - http://www.telerik.com/community/forums/silverlight/drag-and-drop/drag-and-drop-from-listbox-to-canvas-that-has-a-transform.aspx. Let me know if this solves the problem or if you have any futher questions.

Regards,
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
Tom
Top achievements
Rank 1
answered on 21 Oct 2010, 06:56 PM

I could not get the code to work as written.  In GetPropPoint() routine, scaleTransform was NULL.  I added the following line

if (scaleTransform == null
   scaleTransform = new ScaleTransform {ScaleX = transform.Matrix.M11, ScaleY = 
                         transform.Matrix.M22};

It is now dropping correctly, except that it is putting the upper right corner of the object as the mouse position.  Pardon my lack of xaml knowledge, but how do I determine where the upper left corner of my object is realitive to the e.Options.CurrentDragPoint?

0
Accepted
Tsvyatko
Telerik team
answered on 22 Oct 2010, 09:50 AM
Hi Tom,

I guess that what you are trying to achieve is when the item is dropped in the canvas its position corresponds to the mouse position relative to the dragged element. I have modified the sample project to illustrate my idea. Please, have a look and let me know if this works in our scenario.

Best wishes,
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
Tags
DragAndDrop
Asked by
Tom
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
Tom
Top achievements
Rank 1
Share this question
or