A helper class to simplify animation.
        /// <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;

            AnimationHelper.CancelAnimation(this, ContentScaleProperty);
            AnimationHelper.CancelAnimation(this, ContentOffsetXProperty);
            AnimationHelper.CancelAnimation(this, ContentOffsetYProperty);

            this.ContentScale   = newContentScale;
            this.ContentOffsetX = newContentOffsetX;
            this.ContentOffsetY = newContentOffsetY;
        }
        /// <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 newContentZoom, Point contentZoomFocus)
        {
            newContentZoom = Math.Min(Math.Max(newContentZoom, MinimumZoomClamped), MaximumZoom);

            var screenSpaceZoomOffsetX  = (contentZoomFocus.X - ContentOffsetX) * InternalViewportZoom;
            var screenSpaceZoomOffsetY  = (contentZoomFocus.Y - ContentOffsetY) * InternalViewportZoom;
            var contentSpaceZoomOffsetX = screenSpaceZoomOffsetX / newContentZoom;
            var contentSpaceZoomOffsetY = screenSpaceZoomOffsetY / newContentZoom;
            var newContentOffsetX       = contentZoomFocus.X - contentSpaceZoomOffsetX;
            var newContentOffsetY       = contentZoomFocus.Y - contentSpaceZoomOffsetY;

            AnimationHelper.CancelAnimation(this, InternalViewportZoomProperty);
            AnimationHelper.CancelAnimation(this, ContentOffsetXProperty);
            AnimationHelper.CancelAnimation(this, ContentOffsetYProperty);

            this.InternalViewportZoom = newContentZoom;
            this.ContentOffsetX       = newContentOffsetX;
            this.ContentOffsetY       = newContentOffsetY;
            RaiseCanExecuteChanged();
        }
        /// <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);
            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;
            AnimationHelper.StartAnimation(this, ContentScaleProperty, newContentScale, AnimationDuration,
                                           delegate(object sender, EventArgs e)
            {
                enableContentOffsetUpdateFromScale = false;
                ResetViewportZoomFocus();
            });
        }
Example #4
0
 //
 // Fade out the drag zoom rectangle.
 //
 private void FadeOutDragZoomRect()
 {
     AnimationHelper.StartAnimation(_partDragZoomBorder, OpacityProperty, 0.0, 0.1,
                                    delegate { _partDragZoomCanvas.Visibility = Visibility.Collapsed; }, UseAnimations);
 }