开发者

WPF Multitouch DeltaManipulation Mouse Events Equivalent?

i have a small demo app with a grid. this grid contains a image. i use the following code to scale and translate the image with touch.

        private void manipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {

        Matrix matrix = imagematrix.Matrix;

        matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
        matrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y,
            e.ManipulationOrigin.X, e.ManipulationOrigin.Y);

        imagematrix.Matrix = matrix;

        e.Handled = true;

    }

The matrix is placed at rendertra开发者_StackOverflow中文版nsformation property on the image.

I would like to have the same functionality in a other demo app without touch but with mouse event handlers.

I tried something like this for the translation on mouse move but its not the same :(

        protected override void OnMouseMove(MouseEventArgs e)
    {

        if (e.LeftButton == MouseButtonState.Pressed)
        {


            Vector delta = lastPoint - e.GetPosition(canvascontrol);

            Matrix matrix = PART_MATRIX.Matrix;

            if(delta.X > 0)
                matrix.OffsetX += 1;
            else
                matrix.OffsetX -= 1;

            if (delta.Y > 0)
                matrix.OffsetY += 1;
            else
                matrix.OffsetY -= 1;

            imagematrix.Matrix = matrix;

        }

        base.OnMouseMove(e);

    }

lastPoint is the first point onmouseleftbuttondown.

Thanks.


I am not sure, if this is the answer you are looking for but, the Thumb control gives you a DragDelta, if you wrap a Thumb into a template and then assign the template to the image object, or assign the image as a template to the Thumb.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜