/// <inheritdoc/> protected override void OnTouchUp(TouchDevice device, Int64 id, RoutedEventData data) { if (TouchesCaptured.Contains(id) && IsDragging) { HandleCursorUp(id); ReleaseTouchCapture(id); data.Handled = true; } base.OnTouchUp(device, id, data); }
/// <summary> /// Translate and scale the content when it is manipulated. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Input.ManipulationDeltaEventArgs"/> instance containing the event data.</param> private void ContentManipulationProcessor_Affine2DManipulationDelta(object sender, Manipulation2DDeltaEventArgs e) { if (GetMaxScale() == 1) { return; } // The inertia processor can move the content out of bounds. if (sender == _inertiaProcessor) { _translate.X += e.Delta.TranslationX; _translate.Y += e.Delta.TranslationY; _scale.ScaleX *= e.Delta.ScaleX; _scale.ScaleY *= e.Delta.ScaleY; return; } _spring.Stop(this); // Determine what scale to apply to the content. bool returnControlToScatterViewItem = false; double scaleDelta = 1; double newScale = _scale.ScaleX * e.Delta.ScaleX; if (_content.ActualWidth * newScale >= ActualWidth && newScale <= GetMaxScale()) { // If the new scale is within the bounds, just use it directly. scaleDelta = e.Delta.ScaleX; } else if (e.Delta.ScaleX > 1) { // Apply friction to an increasing scale. scaleDelta = 1 + ((e.Delta.ScaleX - 1) * _friction); } else if (e.Delta.ScaleX < 1) { // Apply friction to a decreasing scale. scaleDelta = 1 - ((1 - e.Delta.ScaleX) * _friction); returnControlToScatterViewItem = _scale.ScaleX <= .95; } _scale.ScaleX *= scaleDelta; _scale.ScaleY *= scaleDelta; if (returnControlToScatterViewItem) { // If the content is scaled down to less than the default size, return control back to the ScatterViewItem. if (ScatterViewItem != null) { TouchesCaptured.ToList().ForEach(c => c.Capture(ScatterViewItem)); _overridingScatterViewItem = false; } } // Move the content. _translate.X += e.Delta.TranslationX; _translate.Y += e.Delta.TranslationY; // Get the new bounds of the image. Rect bounds = GetContentBounds(); if (bounds.TopLeft.X > 0 || bounds.BottomRight.X < ActualWidth) { // Apply friction if the content is out of bounds on the x-axis. _translate.X -= e.Delta.TranslationX; _translate.X += e.Delta.TranslationX * _friction; } if (bounds.TopLeft.Y > 0 || bounds.BottomRight.Y < ActualHeight) { // Apply friction if the content is out of bounds on the y-axis. _translate.Y -= e.Delta.TranslationY; _translate.Y += e.Delta.TranslationY * _friction; } }
} // proc OnMouseWheel /// <summary></summary> /// <param name="e"></param> protected override void OnTouchDown(TouchEventArgs e) { base.OnTouchDown(e); if (e.Source is RepeatButton) { return; } if (e.OriginalSource is Border border && String.Compare(border.Name, partItemBorder, false) == 0 && TouchesCaptured.Count() == 0) { lastTouchPosition = e.GetTouchPoint(this).Position.Y; EnsureFocus(); CaptureTouch(e.TouchDevice); } } // proc OnTouchDown