WPF: DragDelta Move distance error resolution after rotating thumb

Source: Internet
Author: User

When the thumb is rotated 90 degrees following the grid, it will fly off when the control is dragged.

<Gridx:name= "Gridmain"Width= "+"Height= " the"Background= "Green"Rendertransformorigin= "0.5,0.5"Canvas.Left= "+"Canvas.Top= "+">                 <Grid.rendertransform>                    <RotateTransformx:name= "Rotate"Angle= "All"></RotateTransform>                </Grid.rendertransform>                <Thumbx:name= "Thumbmain"Opacity= "0.8"DragDelta= "Thumb_dragdelta"></Thumb>            </Grid>
Private void Thumb_dragdelta (object  sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)        {            + e.horizontalchange);             + E.verticalchange);        }

This is due to a non-uniform coordinate system. Canvas.seltleft and Canvas.settop are the Canvas coordinate systems used. The E.horizontalchange and e.verticalchange of the thumb are calculated based on the mouse relative to the thumb's own coordinate system, and the two coordinate systems have a 90 degree angle difference. Will E. Horizontalchange and E.verticalchange into the canvas's coordinate system, drag and drop is no problem. As follows:

Private void Thumb_dragdelta (object  sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)        {            = rotate. Transform (new point (E.horizontalchange, E.verticalchange));             + ptchange.x);             + ptchange.y);        }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.