捏缩放MatrixTransform不尊重父级

时间:2019-06-01 18:49:19

标签: .net wpf

我为带有触摸手势的图像框组装了一个自定义控件。 它具有单击事件,双击向右/向左滑动,然后出现捏捏缩放和平移的问题 一切正常缩放功能存在一个问题,即它不尊重其父级。图片会放大其控件和所有其他控件

我似乎无法弄清楚如何使它尊重父母,对我朝正确的方向有所帮助,对此我深表感谢

我在线找到了一个使用鼠标滚轮进行缩放的控件。除了不适合触摸手势,它完美缩放 我尝试了一部分哲学 但是它不使用矩阵,我正在努力使其与控制功能的其余方式一起使用。所有控件功能都围绕矩阵值工作,以区分滑动和点击

iv研究了一些元素,我认为这是需要做的,但是我很难使它与ManipulationStartingEventArgs一起使用 我是wpf的新手,我只是想把东西拼凑起来。

 //touch control getsters v2
        const double DeltaX = 50, DeltaY = 50, LinearVelocityX = 0.04, MinimumZoom = 1, MaximumZoom = 10;
        private void centerImageView_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
        {
            e.ManipulationContainer = this;
            e.Handled = true;

        }


        private void centerImageView_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {


            //store values of horizontal & vertical cumulative translation
            cumulativeDeltaX = e.CumulativeManipulation.Translation.X;
            cumulativeDeltaY = e.CumulativeManipulation.Translation.Y;
            //store value of linear velocity into horizontal direction  
            linearVelocity = e.Velocities.LinearVelocity.X;

            /// Added from part 2. Scale part.
            // get current matrix of the element.
            Matrix borderMatrix = ((MatrixTransform)this.RenderTransform).Matrix;
            //determine if action is zoom or pinch
            var maxScale = Math.Max(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y);
            //check if not crossing minimum and maximum zoom limit
            if ((maxScale < 1 && borderMatrix.M11 * maxScale > MinimumZoom) ||
            (maxScale > 1 && borderMatrix.M11 * maxScale < MaximumZoom))
            {
                //scale to most recent change (delta) in X & Y 
                borderMatrix.ScaleAt(e.DeltaManipulation.Scale.X,
                        e.DeltaManipulation.Scale.Y,
                        this.ActualWidth / 2,
                        this.ActualHeight / 2);
                //render new matrix

                borderMatrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
                this.RenderTransform = new MatrixTransform(borderMatrix);
            }

        }

        double cumulativeDeltaX, cumulativeDeltaY, linearVelocity;

        private void centerImageView_ManipulationDelta(object sender, System.Windows.Input.ManipulationInertiaStartingEventArgs e)
        {
            e.ExpansionBehavior = new InertiaExpansionBehavior()
            {
                InitialVelocity = e.InitialVelocities.ExpansionVelocity,
                DesiredDeceleration = 10.0 * 96.0 / 1000000.0
            };
        }

        private void centerImageView_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
        {
            bool isRightToLeftSwipe = false; //to determine swipe direction
            if (cumulativeDeltaX < 0)
            {
                //moving from right to left
                isRightToLeftSwipe = true;
            }
            //check if this is swipe gesture
            if (isSwipeGesture(cumulativeDeltaX, cumulativeDeltaY, linearVelocity))
            {
                if (isRightToLeftSwipe)
                {
                    //show previous image
                    nextvImg(null, null);
                }
                else
                {
                    //show next image
                    prevImg(null, null);
                }
            }
        }

        private bool isSwipeGesture(double deltaX, double deltaY, double linearVelocity)
        {
            //imagesListBox.Items.Add(linearVelocity);
            bool result = false;
            if (Math.Abs(deltaY) <= DeltaY && Math.Abs(deltaX) >= DeltaX && Math.Abs(linearVelocity) >= LinearVelocityX)
                result = true;
            return result;
        }

我只希望从其主控件内部调整图像的大小,因此在缩放时,图像停留在其网格的一侧,而不是增大到程序窗口的大小。 我相信我只是缺少了一些东西,并且有一种方法可以做到。 iv看起来在线,他们周围的信息不多。 事实是我知道必须有解决方案,因为您一直在手机上打电话。

0 个答案:

没有答案
相关问题