Drag and drop from listbox to canvas that has a transform

5 posts, 1 answers
  1. David
    David avatar
    7 posts
    Member since:
    Jun 2009

    Posted 21 Sep 2010 Link to this post

    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?
  2. Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 22 Sep 2010 Link to this post

    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
  3. DevCraft banner
  4. David
    David avatar
    7 posts
    Member since:
    Jun 2009

    Posted 22 Sep 2010 Link to this post

    I am zooming using a scale transform


    ZoomTransform = new ScaleTransform();
     
    ZoomTransform.ScaleX *= zoom;
    ZoomTransform.ScaleY *= zoom;
    this.RenderTransform = ZoomTransform;
  5. Answer
    Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 23 Sep 2010 Link to this post

    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
  6. David
    David avatar
    7 posts
    Member since:
    Jun 2009

    Posted 23 Sep 2010 Link to this post

    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!

Back to Top
DevCraft banner