private void OnManipulationDelta(object Sender, ManipulationDeltaEventArgs DeltaRoutedEventArgs) { if (DeltaRoutedEventArgs.CumulativeManipulation.Translation.X < -30) { _gameGrid.HandleMove(MoveDirection.Left); DeltaRoutedEventArgs.Complete(); DeltaRoutedEventArgs.Handled = true; } else if (DeltaRoutedEventArgs.CumulativeManipulation.Translation.X > 30) { _gameGrid.HandleMove(MoveDirection.Right); DeltaRoutedEventArgs.Complete(); DeltaRoutedEventArgs.Handled = true; } else if (DeltaRoutedEventArgs.CumulativeManipulation.Translation.Y < -30) { _gameGrid.HandleMove(MoveDirection.Up); DeltaRoutedEventArgs.Complete(); DeltaRoutedEventArgs.Handled = true; } else if (DeltaRoutedEventArgs.CumulativeManipulation.Translation.Y > 30) { _gameGrid.HandleMove(MoveDirection.Down); DeltaRoutedEventArgs.Complete(); DeltaRoutedEventArgs.Handled = true; } }
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); }
private void UpdateBarPosition(ManipulationDeltaEventArgs e) { double newPosition = BarYPosition + e.DeltaManipulation.Translation.Y; if (newPosition > transitionPosition) { SetImageLock(true); } else { SetImageLock(false); } if (newPosition < maxPosition) { newPosition = maxPosition; e.Complete(); } if (newPosition > closePosition) { newPosition = closePosition; e.Complete(); } BarYPosition = newPosition; }
private void pivot_ManipulationCompleted(object sender, ManipulationDeltaEventArgs e) { var itemsPresenter = this.pivot.GetVisualDescendents().FirstOrDefault(x => x.GetType() == typeof(ItemsPresenter)); var group = itemsPresenter.RenderTransform as TransformGroup; var trans = group.Children.FirstOrDefault(o => o is TranslateTransform) as TranslateTransform; double xvalue = Math.Abs(e.CumulativeManipulation.Translation.X); double yvalue = Math.Abs(e.CumulativeManipulation.Translation.Y); //if (xvalue / yvalue < 2 && yvalue > 80 && trans.X == 0.0) //{ //e.Handled = true; //} Point endPoint = e.ManipulationOrigin; if (endPoint.X - startPoint.X >= 0) { #region Control The Right Side e.Complete(); //e.Handled = true; #endregion } if (endPoint.X - startPoint.X < 0) { #region Control The Left Side e.Complete(); e.Handled = true; #endregion } }
public void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e) { if (e.DeltaManipulation.Translation.X > 0 && myPivot.SelectedIndex == 0) { Debug.WriteLine("left end - stop!"); e.Complete(); } if (e.DeltaManipulation.Translation.X < 0 && myPivot.SelectedIndex == myPivot.Items.Count - 1) { Debug.WriteLine("right end - stop"); e.Complete(); } }
private void Border_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { // optionally suppress zoom if ((ScrollDisabled || !userScalable) && (e.DeltaManipulation.Scale.X != 0.0 || e.DeltaManipulation.Scale.Y != 0.0)) { e.Handled = true; e.Complete(); } // optionally suppress scrolling if (ScrollDisabled && (e.DeltaManipulation.Translation.X != 0.0 || e.DeltaManipulation.Translation.Y != 0.0)) { e.Handled = true; e.Complete(); } }
private void layoutRoot_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { var currentpoint = e.ManipulationOrigin; if (currentpoint.X - _initialPoint.X >= 100) { IncrementValue(); e.Complete(); } else if (_initialPoint.X - currentpoint.X >= 100) { DecrementValue(); e.Complete(); } }
private void DrawingCanvas_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { TouchableImage image = e.OriginalSource as TouchableImage; if (image != null) { Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize); Rect shapeBounds = image.transformGroup.TransformBounds(new Rect(image.RenderSize)); if (e.IsInertial && !containingRect.Contains(shapeBounds)) { e.Complete(); } Point center = new Point(image.RenderSize.Width / 2.0, image.RenderSize.Height / 2.0); //rotation image.rotate.CenterX = center.X; image.rotate.CenterY = center.Y; image.rotate.Angle += e.DeltaManipulation.Rotation; //scale image.scale.CenterX = center.X; image.scale.CenterY = center.Y; image.scale.ScaleX *= e.DeltaManipulation.Scale.X; image.scale.ScaleY *= e.DeltaManipulation.Scale.Y; //trans image.traslation.X += e.DeltaManipulation.Translation.X; image.traslation.Y += e.DeltaManipulation.Translation.Y; } }
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()); } } }
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(); } } } }
// This handles the manipulation data from the touch events. Currently it assumes the zoom and rotation is applied through the center of the element. private void ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { this.EnsureTransform(); ManipulationDelta currentDelta = e.DeltaManipulation; // Always use the element's center point as the origin of the manipulation deltas. Point origin = new Point(this.AssociatedObject.ActualWidth / 2, this.AssociatedObject.ActualHeight / 2); // Compute the manipulation center in element space. Point center = this.FullTransformValue.Transform(origin); this.ApplyScaleTransform(currentDelta.Scale.X, currentDelta.Scale.Y, center); this.ApplyRotationTransform(currentDelta.Rotation, center); this.ApplyTranslateTransform(currentDelta.Translation.X, currentDelta.Translation.Y); FrameworkElement container = (FrameworkElement)e.ManipulationContainer; // If constraining to bounds, and the element leaves its parent bounds, then stop the inertia. Rect parentBounds = new Rect(container.RenderSize); Rect childBounds = this.AssociatedObject.TransformToVisual(container).TransformBounds(new Rect(this.AssociatedObject.RenderSize)); if (e.IsInertial && this.ConstrainToParentBounds && !parentBounds.Contains(childBounds)) { e.Complete(); } e.Handled = true; }
void imageView_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { ShowImageView imageView = sender as ShowImageView; if (imageView == null) { return; } if (Math.Abs(e.CumulativeManipulation.Translation.Y) < 15) { e.Handled = true; if (e.CumulativeManipulation.Translation.X < -10) { Size size = imageView.RenderSize; Point center = imageView.PointToScreen(new Point(imageView.ActualWidth / 2, imageView.ActualHeight / 2)); ShowImageModel model = imageView.Model as ShowImageModel; if (model != null) { OnAddImageCommand(center, size, model.Text); } e.Complete(); } } }
void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { Rectangle rectToMove = e.OriginalSource as Rectangle; Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix; //rectsMatrix.RotateAt(e.DeltaManipulation.Rotation, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); //rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.X, // e.ManipulationOrigin.X, e.ManipulationOrigin.Y); rectsMatrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); //rectToMove.RenderTransform = new MatrixTransform(rectsMatrix); foreach (var rectangle in rectangles) { rectangle.RenderTransform = new MatrixTransform(rectsMatrix); } Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize); Rect shapeBounds = rectToMove.RenderTransform.TransformBounds(new Rect(rectToMove.RenderSize)); if (e.IsInertial && !containingRect.Contains(shapeBounds)) { e.Complete(); } e.Handled = true; }
void mapView_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { ShowZoneView zoneView = sender as ShowZoneView; if (zoneView == null || !canMapBeTriggered) { return; } if (Math.Abs(e.CumulativeManipulation.Translation.Y) < 15) { e.Handled = true; if (e.CumulativeManipulation.Translation.X < -10) { Size size = zoneView.RenderSize; Point center = zoneView.PointToScreen(new Point(zoneView.ActualWidth / 2, zoneView.ActualHeight / 2)); canMapBeTriggered = false; e.Complete(); OnAddMapCommand(center, size); } } else { canMapBeTriggered = false; } }
private void Image_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { if (this.dragImage != null && this.isMoveToy) { e.Handled = true; e.Complete(); } }
private void Window_ManipulationDelta_1(object sender, ManipulationDeltaEventArgs e) { if (e.OriginalSource is Rectangle) { Rectangle rectToMove; // rectToMove = e.OriginalSource as Rectangle; //else // rectToMove = ((MatrixTransform)(e.OriginalSource as TextBlock).RenderTransform).Matrix; Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix; //rectsMatrix.RotateAt(e.DeltaManipulation.Rotation, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.X, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); rectsMatrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); rectToMove.RenderTransform = new MatrixTransform(rectsMatrix); Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize); Rect shapeBounds = rectToMove.RenderTransform.TransformBounds(new Rect(rectToMove.RenderSize)); if (e.IsInertial && !containingRect.Contains(shapeBounds)) { e.Complete(); } e.Handled = true; SelectedRec = e.OriginalSource as Rectangle; SelectedBor = null; } if (e.OriginalSource is Border) { var element = e.Source as FrameworkElement; var transformation = element.RenderTransform as MatrixTransform; var matrix = transformation == null ? Matrix.Identity : transformation.Matrix; matrix.RotateAt(e.DeltaManipulation.Rotation, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); matrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.X, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); element.RenderTransform = new MatrixTransform(matrix); e.Handled = true; SelectedRec = null; SelectedBor = e.OriginalSource as Border; } }
private void pivot_ManipulationCompleted(object sender, ManipulationDeltaEventArgs e) { Point endPoint = e.ManipulationOrigin; if (endPoint.X - startPoint.X >= 0) { #region Control Right Side e.Complete(); e.Handled = true; #endregion } if (endPoint.X - startPoint.X < 0) { #region Control Left Side e.Complete(); e.Handled = true; #endregion } }
private void AssociatedObject_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { if (e.IsInertial) { Point position = new Point(e.ManipulationOrigin.X, e.ManipulationOrigin.Y); if (position.X - position.X >= 300) { e.Complete(); } } }
void GridMovementDelta(object sender, ManipulationDeltaEventArgs e) { Point currentpoint = e.ManipulationOrigin; System.Diagnostics.Debug.WriteLine(currentpoint.X - initialpoint.X); if (currentpoint.X - initialpoint.X >= 500) //500 is the threshold value, where you want to trigger the swipe right event { System.Diagnostics.Debug.WriteLine("Swipe Right"); //TabControl.SpinToPrevious(); e.Complete(); } if (currentpoint.X - initialpoint.X <= -500) { System.Diagnostics.Debug.WriteLine("Swipe Left"); //TabControl.SpinToPrevious(); e.Complete(); } }
void layoutRoot_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { var currentpoint = e.ManipulationOrigin; if (currentpoint.X - _initialPoint.X >= 150) { if (this.Value != null) { this.Value = Convert.ToDateTime(this.Value).AddDays(-1); } e.Complete(); } else if (_initialPoint.X - currentpoint.X >= 150) { if (this.Value != null) { this.Value = Convert.ToDateTime(this.Value).AddDays(+1); } e.Complete(); } }
private void container_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { mTranslate.X += e.DeltaManipulation.Translation.X; if (e.IsInertial) { bool shoudStop = e.Velocities.LinearVelocity.X < 0 && mTranslate.X < -(mCards.Count() - 2) * (mCardWidth + Gap); shoudStop |= e.Velocities.LinearVelocity.X > 0 && mTranslate.X > mCardWidth * 2; if (shoudStop) { e.Complete(); } } }
/// <summary>Overwrite panning and zoom implementation fo the scroll viewer.</summary> /// <param name="e"></param> protected override void OnManipulationDelta(ManipulationDeltaEventArgs e) { touchTransformMatrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); touchTransformMatrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); UpdateContentTransform(touchTransformMatrix, e.ManipulationOrigin); if (e.IsInertial) { e.Complete(); } e.Handled = true; } // proc OnManipulationDelta
void UserControl_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { try { // Get the Rectangle and its RenderTransform matrix. Grid rectToMove = e.OriginalSource as Grid; 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); //For CloseButton Only 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(); } } catch (Exception error) { //throw error exception } e.Handled = true; }
//</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; }
private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e) { // Get the UI element and its RenderTransform matrix. var uiElement = e.OriginalSource as UIElement; if (uiElement != null) { var matrixTransform = (MatrixTransform)uiElement.RenderTransform; var matrix = matrixTransform.Matrix; // Rotate the item. matrix.RotateAt(e.DeltaManipulation.Rotation, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); // Resize the item. Keep it square // so use only the X value of Scale. matrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.X, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); // Move the item. matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); // Apply the changes to the item. matrixTransform.Matrix = matrix; // Update adorner UpdateAdorner(uiElement, matrix); var manipulationContainer = (FrameworkElement)e.ManipulationContainer; var containingRect = new Rect(manipulationContainer.RenderSize); var elementBounds = uiElement.RenderTransform.TransformBounds(new Rect(uiElement.RenderSize)); // Check if the ScatterViewItem is completely in the ScatterView. // If it is not and intertia is occuring, stop the manipulation. if (e.IsInertial && !containingRect.Contains(elementBounds)) { //e.ReportBoundaryFeedback(e.DeltaManipulation); e.Complete(); } } e.Handled = true; }
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"); }
/// <summary> /// Event fired when the user wiggles their finger after the initial press /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">Event arguments.</param> private void OnOwnerManipulationDelta(object sender, ManipulationDeltaEventArgs e) { // If the context menu is open already, then complete this gesture // good to do for owner of type ListBox, Pivot, Panorama if (IsOpen == true) { e.Complete(); e.Handled = true; } // If there is a non-negative drag or multi-finger, then cancel the timer if (Math.Abs(e.DeltaManipulation.Translation.X) != ContextMenuCancelMovement || Math.Abs(e.DeltaManipulation.Translation.Y) != ContextMenuCancelMovement || Math.Abs(e.DeltaManipulation.Scale.X) != 0 || Math.Abs(e.DeltaManipulation.Scale.Y) != 0) { tapAndHoldTimer.Stop(); } }
private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e) { // Get the UI element and its RenderTransform matrix var uiElement = e.OriginalSource as UIElement; if (uiElement != null) { var matrixTransform = (MatrixTransform)uiElement.RenderTransform; var matrix = matrixTransform.Matrix; // Rotate the element matrix.RotateAt(e.DeltaManipulation.Rotation, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); // Resize the element matrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); // Move the element matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); // Apply the changes to the element matrixTransform.Matrix = matrix; var manipulationContainer = (FrameworkElement)e.ManipulationContainer; var containingRect = new Rect(manipulationContainer.RenderSize); var shapeBounds = uiElement.RenderTransform.TransformBounds(new Rect(uiElement.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)) { e.Complete(); } } e.Handled = true; }
void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs manipulation) { //Get the Rectangle and its RenderTransform matrix. Rectangle rectToMove = manipulation.OriginalSource as Rectangle; Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix; //Rotate the Rectangle. rectsMatrix.RotateAt(manipulation.DeltaManipulation.Rotation, manipulation.ManipulationOrigin.X, manipulation.ManipulationOrigin.Y); //Resize the Rectangle. Keep it square //so use only the X value of Scale. rectsMatrix.ScaleAt(manipulation.DeltaManipulation.Scale.X, manipulation.DeltaManipulation.Scale.X, manipulation.ManipulationOrigin.X, manipulation.ManipulationOrigin.Y); //Move the Rectangle rectsMatrix.Translate(manipulation.DeltaManipulation.Translation.X, manipulation.DeltaManipulation.Translation.Y); //Apply the changes to the Rectangle. rectToMove.RenderTransform = new MatrixTransform(rectsMatrix); Rect containRect = new Rect(((FrameworkElement)manipulation.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 inertia is occuring, stop the manipulation if (manipulation.IsInertial && !containRect.Contains(shapeBounds)) { manipulation.Complete(); } manipulation.Handled = true; }
//Behandeln der Manipulationsdaten, die während der des Ziehens des Stackpanels auftreten void PhoneApplicationPage_ManupualtionDelta(object sender, ManipulationDeltaEventArgs e) { e.Handled = true; //aktuelle Koordinaten des Stackpanels aktualisieren _currentX += e.DeltaManipulation.Translation.X; _currentY += e.DeltaManipulation.Translation.Y; //ermitteln wo sich die Ränder des bewegten Stackpanels befinden double rightCorner = _currentX + stackForDrag.ActualWidth; double leftCorner = _currentX; double bottomCorner = _currentY + stackForDrag.ActualHeight; double upperCorner = _currentY; //prüfen, ob Stackpanels außerhalb seines Containers gezogen wurde if (rightCorner <= _containerWidth && bottomCorner <= _containerHeight && leftCorner >= 0 && upperCorner >= 0) { //stackpanel in X-Richtung bewegen _translation.X += e.DeltaManipulation.Translation.X; _translation.Y += e.DeltaManipulation.Translation.Y; } else { //Stackpanel auf den Startpunkt zurücksetzen _translation.X = stackForDrag.RenderTransformOrigin.X; _translation.Y = stackForDrag.RenderTransformOrigin.Y; //aktuelle Position zurücksetzen _currentX = 0; _currentY = 0; //setzen des Status, dass Stackpanel außerhalb seines Containers gezogen wurde e.Complete(); } //Ausgabe der aktuellen Koordinaten des Stackpanels txt_mouseX.Text = _currentX.ToString(); txt_mouseY.Text = _currentY.ToString(); }