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 -
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
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