private void OnManipulationDelta(ManipulationDeltaRoutedEventArgs e) { e.Handled = true; try { float?factor = null; var offsetX = startHorizontalOffset - e.Cumulative.Translation.X; var offsetY = startVerticalOffset - e.Cumulative.Translation.Y; var currentScale = e.Cumulative.Scale; if (currentScale != 1F) { factor = startZoomFactor * currentScale; offsetX = offsetX * currentScale + startPosition.X * (currentScale - 1F); offsetY = offsetY * currentScale + startPosition.Y * (currentScale - 1F); } AssociatedViewer.ChangeView(offsetX, offsetY, factor); } catch (Exception ex) { Debug.WriteLine($"Failed to reflect changes of ManipulationDalta.\r\n{ex}"); } }
private void RestoreInViewerPosition(Point inViewerPosition, Point inSelectorPosition, float viewerZoomFactor, bool checkesItemInViewport = false) { var offsetX = inSelectorPosition.X * viewerZoomFactor - inViewerPosition.X; var offsetY = inSelectorPosition.Y * viewerZoomFactor - inViewerPosition.Y; if (checkesItemInViewport) { var left = offsetX / viewerZoomFactor; var right = left + AssociatedViewer.ActualWidth / viewerZoomFactor; var top = offsetY / viewerZoomFactor; var bottom = top + AssociatedViewer.ActualHeight / viewerZoomFactor; var existsItemInViewport = AssociatedSelector.GetDescendantsOfType <SelectorItem>() .Select(item => item.TransformToVisual(AssociatedSelector).TransformPoint(default(Point))) .Any(position => (left < position.X) && (position.X < right) && (top < position.Y) && (position.Y < bottom)); if (!existsItemInViewport) { return; } } try { AssociatedViewer.ChangeView(offsetX, offsetY, viewerZoomFactor); } catch (Exception ex) { Debug.WriteLine($"Failed to restore position and zoom factor.\r\n{ex}"); } }
private void OnManipulationDelta(ManipulationDeltaRoutedEventArgs e) { e.Handled = true; try { float?factor = null; var offsetX = _startHorizontalOffset - e.Cumulative.Translation.X; var offsetY = _startVerticalOffset - e.Cumulative.Translation.Y; var currentScale = e.Cumulative.Scale; if (currentScale != 1F) { factor = _startZoomFactor * currentScale; offsetX = offsetX * currentScale + _startPosition.X * (currentScale - 1F); offsetY = offsetY * currentScale + _startPosition.Y * (currentScale - 1F); } //Debug.WriteLine("OffsetX:{0} OffsetY:{1} factor:{2}", offsetX, offsetY, factor); AssociatedViewer.ChangeView(offsetX, offsetY, factor); } catch (Exception ex) { Debug.WriteLine("Failed to reflect changes of ManipulationDalta. {0}", ex); throw new Exception("Failed to reflect changes of ManipulationDelta.", ex); } }
private void OnPointerMoved(PointerRoutedEventArgs e) { e.Handled = true; var position = e.GetCurrentPoint(AssociatedViewer).Position; var offsetX = startHorizontalOffsetPosition - position.X; var offsetY = startVerticalOffsetPosition - position.Y; AssociatedViewer.ChangeView(offsetX, offsetY, null); }
private void OnPointerMoved(PointerRoutedEventArgs e) { e.Handled = true; var position = e.GetCurrentPoint(AssociatedViewer).Position; var offsetX = _startHorizontalOffsetPosition - position.X; var offsetY = _startverticalOffsetPosition - position.Y; //Debug.WriteLine("OffsetX:{0} OffsetY:{1}", offsetX, offsetY); AssociatedViewer.ChangeView(offsetX, offsetY, null); }