protected override void OnManipulationDelta(ManipulationDeltaEventArgs args)
        {
            if (!manipulationDeltaInProgress)
            {
                IsActive = true;

                if (!tapInertiaInProgess)
                {
                    SelectedIndex = -1;
                }
            }

            manipulationDeltaInProgress = true;

            // This is the fake inertia from a tap
            if (tapInertiaInProgess)
            {
                VerticalOffset -= args.DeltaManipulation.Translation.Y;
            }

            // All other direct manipulation and inertia
            else
            {
                // For non-wrappable panel, check for end of the line
                if (!isWrappableStackPanel)
                {
                    double newVerticalOffset = VerticalOffset - inertiaDirection * args.DeltaManipulation.Translation.Y;

                    if (FractionalCenteredIndexFromVerticalOffset(newVerticalOffset, false) < 0)
                    {
                        double verticalOffsetIncrement = VerticalOffset - VerticalOffsetFromCenteredIndex(0);
                        double verticalOffsetExcess    = args.DeltaManipulation.Translation.Y - verticalOffsetIncrement;
                        VerticalOffset -= verticalOffsetIncrement;
                        SelectedIndex   = 0;
                        args.ReportBoundaryFeedback(new ManipulationDelta(new Vector(0, verticalOffsetExcess), 0, new Vector(), new Vector()));
                        args.Complete();
                    }
                    else if (FractionalCenteredIndexFromVerticalOffset(newVerticalOffset, false) > Items.Count - 1)
                    {
                        double verticalOffsetIncrement = VerticalOffsetFromCenteredIndex(Items.Count - 1) - VerticalOffset;
                        double verticalOffsetExcess    = args.DeltaManipulation.Translation.Y - verticalOffsetIncrement;
                        VerticalOffset += verticalOffsetIncrement;
                        SelectedIndex   = Items.Count - 1;
                        args.ReportBoundaryFeedback(new ManipulationDelta(new Vector(0, verticalOffsetExcess), 0, new Vector(), new Vector()));
                        args.Complete();
                    }
                }

                // Here's where scrolling might reverse itself
                if (args.IsInertial && inertiaToUnknownIndex && !reverseInertiaChecked)
                {
                    CheckForBackupManeuver(VerticalOffset, args.DeltaManipulation.Translation.Y, args.Velocities.LinearVelocity.Y);
                }

                // This is the normal direct manipulation and inertia
                VerticalOffset -= inertiaDirection * args.DeltaManipulation.Translation.Y;
            }

            base.OnManipulationDelta(args);
        }
示例#2
0
        void image_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            var element = e.Source as FrameworkElement;

            if (element != null)
            {
                var deltaManipulation       = e.DeltaManipulation;
                var matrix                  = ((MatrixTransform)element.RenderTransform).Matrix;
                System.Windows.Point center = new System.Windows.Point(element.ActualWidth / 2, element.ActualHeight / 2);
                center = matrix.Transform(center);
                matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y);
                matrix.RotateAt(e.DeltaManipulation.Rotation, center.X, center.Y);
                matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
                ((MatrixTransform)element.RenderTransform).Matrix = matrix;
                e.Handled = true;
                if (e.IsInertial)
                {
                    Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);
                    Rect shapeBounds    = element.RenderTransform.TransformBounds(new Rect(element.RenderSize));
                    if (e.IsInertial && !containingRect.Contains(shapeBounds))
                    {
                        e.ReportBoundaryFeedback(e.DeltaManipulation);
                        e.Complete();
                    }
                }
            }
        }
        private void canvas_PadControl_wheel_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            var element = e.Source as FrameworkElement;

            if (element != null)
            {
                if (e.IsInertial)
                {
                    Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);

                    Rect shapeBounds = element.RenderTransform.TransformBounds(new Rect(element.RenderSize));
                    if (e.IsInertial && !containingRect.Contains(shapeBounds))
                    {
                        e.ReportBoundaryFeedback(e.DeltaManipulation);
                        e.Complete();
                    }
                }
                try
                {
                    Matrix matrix = element.RenderTransform.Value;
                    Point  center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
                    center = matrix.Transform(center);  //设置中心点
                    // 处理旋转
                    matrix.RotateAt(e.DeltaManipulation.Rotation / 5, center.X, center.Y);

                    element.RenderTransform = new MatrixTransform(matrix);
                    e.Handled      = true;
                    label8.Content = e.DeltaManipulation.Rotation / 5;
                }
                catch (Exception ei)
                {
                    MessageBox.Show(ei.ToString());
                }
            }
        }
        //</SnippetManipulationPivot>

        //<SnippetReportBoundaryFeedback>
        void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            Rectangle rectToMove = e.OriginalSource as Rectangle;
            Vector    overshoot;

            // When the element crosses the boundary of the window, check whether
            // the manipulation is in inertia.  If it is, complete the manipulation.
            // Otherwise, report the boundary feedback.
            if (CalculateOvershoot(rectToMove, e.ManipulationContainer, out overshoot))
            {
                if (e.IsInertial)
                {
                    e.Complete();
                    e.Handled = true;
                    return;
                }
                else
                {
                    //Report that the element hit the boundary
                    e.ReportBoundaryFeedback(new ManipulationDelta(overshoot, 0, new Vector(), new Vector()));
                }
            }

            // Move the element as usual.

            // Get the Rectangle and its RenderTransform matrix.
            Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix;

            // Rotate the Rectangle.
            rectsMatrix.RotateAt(e.DeltaManipulation.Rotation,
                                 e.ManipulationOrigin.X,
                                 e.ManipulationOrigin.Y);

            // Resize the Rectangle.  Keep it square
            // so use only the X value of Scale.
            rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X,
                                e.DeltaManipulation.Scale.X,
                                e.ManipulationOrigin.X,
                                e.ManipulationOrigin.Y);

            // Move the Rectangle.
            rectsMatrix.Translate(e.DeltaManipulation.Translation.X,
                                  e.DeltaManipulation.Translation.Y);

            // Apply the changes to the Rectangle.
            rectToMove.RenderTransform = new MatrixTransform(rectsMatrix);

            e.Handled = true;
        }
示例#5
0
        private void AssociatedObject_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            //this just gets the source.
            // I cast it to FE because I wanted to use ActualWidth for Center. You could try RenderSize as alternate
            var element = e.Source as FrameworkElement;

            if (element != null)
            {
                //e.DeltaManipulation has the changes
                // Scale is a delta multiplier; 1.0 is last size,  (so 1.1 == scale 10%, 0.8 = shrink 20%)
                // Rotate = Rotation, in degrees
                // Pan = Translation, == Translate offset, in Device Independent Pixels

                var deltaManipulation = e.DeltaManipulation;
                var matrix            = ((MatrixTransform)element.RenderTransform).Matrix;
                // find the old center; arguaby this could be cached
                Point center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
                // transform it to take into account transforms from previous manipulations
                center = matrix.Transform(center);
                //this will be a Zoom.
                matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y);
                // Rotation
                matrix.RotateAt(e.DeltaManipulation.Rotation, center.X, center.Y);
                //Translation (pan)
                matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);

                ((MatrixTransform)element.RenderTransform).Matrix = matrix;

                e.Handled = true;


                if (e.IsInertial)
                {
                    Rect containingRect = new Rect(0, 0, System.Windows.SystemParameters.PrimaryScreenWidth, System.Windows.SystemParameters.PrimaryScreenHeight);

                    Rect shapeBounds = element.RenderTransform.TransformBounds(new Rect(element.RenderSize));
                    //Console.WriteLine(center.X.ToString() + " " + center.Y.ToString() + " " + containingRect.Contains(center).ToString());
                    // Check if the element is completely in the window.
                    // If it is not and intertia is occurring, stop the manipulation.
                    if (e.IsInertial && !containingRect.Contains(shapeBounds))
                    {
                        e.ReportBoundaryFeedback(e.DeltaManipulation);
                    }
                }
            }
        }
示例#6
0
        public void ManipulationDelta(DrawingCanvas drawingCanvas, ManipulationDeltaEventArgs e)
        {
            // Get the Rectangle and its RenderTransform matrix.
            Rectangle rectToMove  = e.OriginalSource as Rectangle;
            Matrix    rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix;

            // Rotate the Rectangle.
            rectsMatrix.RotateAt(e.DeltaManipulation.Rotation,
                                 e.ManipulationOrigin.X,
                                 e.ManipulationOrigin.Y);

            // Resize the Rectangle.  Keep it square
            // so use only the X value of Scale.
            rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X,
                                e.DeltaManipulation.Scale.X,
                                e.ManipulationOrigin.X,
                                e.ManipulationOrigin.Y);

            // Move the Rectangle.
            rectsMatrix.Translate(e.DeltaManipulation.Translation.X,
                                  e.DeltaManipulation.Translation.Y);

            // Apply the changes to the Rectangle.
            rectToMove.RenderTransform = new MatrixTransform(rectsMatrix);

            Rect containingRect =
                new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);

            Rect shapeBounds =
                rectToMove.RenderTransform.TransformBounds(
                    new Rect(rectToMove.RenderSize));

            // Check if the rectangle is completely in the window.
            // If it is not and intertia is occuring, stop the manipulation.
            if (e.IsInertial && !containingRect.Contains(shapeBounds))
            {
                e.Complete();
                e.ReportBoundaryFeedback(e.DeltaManipulation);
            }


            e.Handled = true;
            System.Diagnostics.Debug.WriteLine("ManipulationDelta");
        }
        private void image_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            //this just gets the source.
            // I cast it to FE because I wanted to use ActualWidth for Center. You could try RenderSize as alternate
            var element = e.Source as FrameworkElement;

            if (element != null)
            {
                //e.DeltaManipulation has the changes
                // Scale is a delta multiplier; 1.0 is last size,  (so 1.1 == scale 10%, 0.8 = shrink 20%)
                // Rotate = Rotation, in degrees
                // Pan = Translation, == Translate offset, in Device Independent Pixels
                var   deltaManipulation = e.DeltaManipulation;
                var   matrix            = ((MatrixTransform)element.RenderTransform).Matrix;
                Point center            = new Point(e.ManipulationOrigin.X, e.ManipulationOrigin.Y);

                // this will be a Zoom.
                if (!IsScaleDisabled) // scale is enabled
                {
                    if (element as TouchImage != null)
                    {
                        if ((element as TouchImage).IsScaleDisable)
                        {
                            return;                                         // scale olayı bu canvas için kapalı ise
                        }
                    }
                    matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y);
                }
                // Rotation
                if (!IsRotateDisabled) // rotation is enabled
                {
                    if (element as TouchImage != null)
                    {
                        if ((element as TouchImage).IsRotateDisabled)
                        {
                            return;                                           // scale olayı bu canvas için kapalı ise
                        }
                    }
                    matrix.RotateAt(e.DeltaManipulation.Rotation, center.X, center.Y);
                }
                // Translation (pan)
                if (!IsTranslateDisabled) // translation is enabled
                {
                    if (element as TouchImage != null)
                    {
                        if ((element as TouchImage).IsTranslateDisabled)
                        {
                            return;                                              // scale olayı bu canvas için kapalı ise
                        }
                    }
                    matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
                }

                //Determinant = 1 ise ozaman büyüklük geldiği büyüklüktür.
                //Determinant bir child ' ın küçültme ve büyütme faktörüdür.
                if ((matrix.Determinant >= MinScaleFactor) && (matrix.Determinant <= MaxScaleFactor || MaxScaleFactor == 0))
                {
                    ((MatrixTransform)element.RenderTransform).Matrix = matrix;
                }

                var videoPlayer = element as TouchVideoPlayer;
                if (videoPlayer != null)
                {
                    videoPlayer.Volume = Math.Max(0, Math.Min(matrix.Determinant, 1)); //bind the volume to the render size of the video in the screen
                }
                e.Handled = true;

                if (e.IsInertial)
                {
                    Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);
                    Rect shapeBounds    = element.RenderTransform.TransformBounds(new Rect(element.RenderSize));
                    // Check if the element is completely in the window.
                    // If it is not and intertia is occuring, stop the manipulation.
                    if (e.IsInertial && !containingRect.Contains(shapeBounds) && !containingRect.IntersectsWith(shapeBounds))
                    {
                        //Report that we have gone over our boundary
                        e.ReportBoundaryFeedback(e.DeltaManipulation);
                        OnthrownOut(element);
                        // comment out this line to see the Window 'shake' or 'bounce'
                        // similar to Win32 Windows when they reach a boundary; this comes for free in .NET 4
                        e.Complete();
                    }
                }
            }
        }
 protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
 {
     base.OnManipulationDelta(e);
     e.ReportBoundaryFeedback(new ManipulationDelta(new Vector(0, 0), 0, new Vector(0, 0), new Vector(0, 0)));
 }