/// <summary> /// Zoom to the specified scale and move the specified focus point to the center of the viewport. /// </summary> private void AnimatedZoomPointToViewportCenter(double newContentScale, Point contentZoomFocus, EventHandler callback) { newContentScale = Math.Min(Math.Max(newContentScale, MinContentScale), MaxContentScale); ZoomPanAnimationHelper.CancelAnimation(this, ContentZoomFocusXProperty); ZoomPanAnimationHelper.CancelAnimation(this, ContentZoomFocusYProperty); ZoomPanAnimationHelper.CancelAnimation(this, ViewportZoomFocusXProperty); ZoomPanAnimationHelper.CancelAnimation(this, ViewportZoomFocusYProperty); ContentZoomFocusX = contentZoomFocus.X; ContentZoomFocusY = contentZoomFocus.Y; ViewportZoomFocusX = (ContentZoomFocusX - ContentOffsetX) * ContentScale; ViewportZoomFocusY = (ContentZoomFocusY - ContentOffsetY) * ContentScale; // // When zooming about a point make updates to ContentScale also update content offset. // _enableContentOffsetUpdateFromScale = true; ZoomPanAnimationHelper.StartAnimation(this, ContentScaleProperty, newContentScale, AnimationDuration, delegate(object sender, EventArgs e) { _enableContentOffsetUpdateFromScale = false; if (callback != null) { callback(this, EventArgs.Empty); } }); ZoomPanAnimationHelper.StartAnimation(this, ViewportZoomFocusXProperty, ViewportWidth / 2, AnimationDuration); ZoomPanAnimationHelper.StartAnimation(this, ViewportZoomFocusYProperty, ViewportHeight / 2, AnimationDuration); }
/// <summary> /// Zoom in/out centered on the specified point (in content coordinates). /// The focus point is kept locked to it's on screen position (ala google maps). /// </summary> public void AnimatedZoomAboutPoint(double newContentScale, Point contentZoomFocus) { newContentScale = Math.Min(Math.Max(newContentScale, MinContentScale), MaxContentScale); ZoomPanAnimationHelper.CancelAnimation(this, ContentZoomFocusXProperty); ZoomPanAnimationHelper.CancelAnimation(this, ContentZoomFocusYProperty); ZoomPanAnimationHelper.CancelAnimation(this, ViewportZoomFocusXProperty); ZoomPanAnimationHelper.CancelAnimation(this, ViewportZoomFocusYProperty); ContentZoomFocusX = contentZoomFocus.X; ContentZoomFocusY = contentZoomFocus.Y; ViewportZoomFocusX = (ContentZoomFocusX - ContentOffsetX) * ContentScale; ViewportZoomFocusY = (ContentZoomFocusY - ContentOffsetY) * ContentScale; // // When zooming about a point make updates to ContentScale also update content offset. // _enableContentOffsetUpdateFromScale = true; ZoomPanAnimationHelper.StartAnimation(this, ContentScaleProperty, newContentScale, AnimationDuration, delegate(object sender, EventArgs e) { _enableContentOffsetUpdateFromScale = false; ResetViewportZoomFocus(); }); }
/// <summary> /// Use animation to center the view on the specified point (in content coordinates). /// </summary> public void AnimatedSnapTo(Point contentPoint) { double newX = contentPoint.X - (this.ContentViewportWidth / 2); double newY = contentPoint.Y - (this.ContentViewportHeight / 2); ZoomPanAnimationHelper.StartAnimation(this, ContentOffsetXProperty, newX, AnimationDuration); ZoomPanAnimationHelper.StartAnimation(this, ContentOffsetYProperty, newY, AnimationDuration); }
/// <summary> /// Instantly center the view on the specified point (in content coordinates). /// </summary> public void SnapTo(Point contentPoint) { ZoomPanAnimationHelper.CancelAnimation(this, ContentOffsetXProperty); ZoomPanAnimationHelper.CancelAnimation(this, ContentOffsetYProperty); this.ContentOffsetX = contentPoint.X - (this.ContentViewportWidth / 2); this.ContentOffsetY = contentPoint.Y - (this.ContentViewportHeight / 2); }
/// <summary> /// Instantly center the view on the specified point (in content coordinates). /// </summary> public void SnapContentOffsetTo(Point contentOffset) { ZoomPanAnimationHelper.CancelAnimation(this, ContentOffsetXProperty); ZoomPanAnimationHelper.CancelAnimation(this, ContentOffsetYProperty); this.ContentOffsetX = contentOffset.X; this.ContentOffsetY = contentOffset.Y; }
/// <summary> /// Zoom to the specified scale and move the specified focus point to the center of the viewport. /// </summary> private void ZoomPointToViewportCenter(double newContentScale, Point contentZoomFocus) { newContentScale = Math.Min(Math.Max(newContentScale, MinContentScale), MaxContentScale); ZoomPanAnimationHelper.CancelAnimation(this, ContentScaleProperty); ZoomPanAnimationHelper.CancelAnimation(this, ContentOffsetXProperty); ZoomPanAnimationHelper.CancelAnimation(this, ContentOffsetYProperty); this.ContentScale = newContentScale; this.ContentOffsetX = contentZoomFocus.X - (ContentViewportWidth / 2); this.ContentOffsetY = contentZoomFocus.Y - (ContentViewportHeight / 2); }
/// <summary> /// Zoom in/out centered on the specified point (in content coordinates). /// The focus point is kept locked to it's on screen position (ala google maps). /// </summary> public void ZoomAboutPoint(double newContentScale, Point contentZoomFocus) { newContentScale = Math.Min(Math.Max(newContentScale, MinContentScale), MaxContentScale); double screenSpaceZoomOffsetX = (contentZoomFocus.X - ContentOffsetX) * ContentScale; double screenSpaceZoomOffsetY = (contentZoomFocus.Y - ContentOffsetY) * ContentScale; double contentSpaceZoomOffsetX = screenSpaceZoomOffsetX / newContentScale; double contentSpaceZoomOffsetY = screenSpaceZoomOffsetY / newContentScale; double newContentOffsetX = contentZoomFocus.X - contentSpaceZoomOffsetX; double newContentOffsetY = contentZoomFocus.Y - contentSpaceZoomOffsetY; ZoomPanAnimationHelper.CancelAnimation(this, ContentScaleProperty); ZoomPanAnimationHelper.CancelAnimation(this, ContentOffsetXProperty); ZoomPanAnimationHelper.CancelAnimation(this, ContentOffsetYProperty); this.ContentScale = newContentScale; this.ContentOffsetX = newContentOffsetX; this.ContentOffsetY = newContentOffsetY; }