/// <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); AnimationHelper.StartAnimation(this, ContentOffsetXProperty, newX, AnimationDuration); AnimationHelper.StartAnimation(this, ContentOffsetYProperty, newY, AnimationDuration); }
/// <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); AnimationHelper.CancelAnimation(this, ContentZoomFocusXProperty); AnimationHelper.CancelAnimation(this, ContentZoomFocusYProperty); AnimationHelper.CancelAnimation(this, ViewportZoomFocusXProperty); AnimationHelper.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; if (ContentScale == newContentScale) { ContentScale *= 1.0000000001; // Change the scale slightly so our animation still works. } AnimationHelper.StartAnimation(this, ContentScaleProperty, newContentScale, AnimationDuration, delegate(object sender, EventArgs e) { enableContentOffsetUpdateFromScale = false; if (callback != null) { callback(this, EventArgs.Empty); } }); double newViewportZoomFocusX = ViewportWidth / 2; double newViewportZoomFocusY = ViewportHeight / 2; if (newViewportZoomFocusY == ViewportZoomFocusY) { ViewportZoomFocusY += 1; } if (newViewportZoomFocusX == ViewportZoomFocusX) { ViewportZoomFocusX += 1; } AnimationHelper.StartAnimation(this, ViewportZoomFocusXProperty, newViewportZoomFocusX, AnimationDuration); AnimationHelper.StartAnimation(this, ViewportZoomFocusYProperty, newViewportZoomFocusY, AnimationDuration); }