Пример #1
0
        private static void ContentOffsetY_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ScrollBox c = (ScrollBox)o;

            c.UpdateTranslationY();

            if (!c.disableContentFocusSync)
            {
                //
                // Normally want to automatically update content focus when content offset changes.
                // Although this is disabled using 'disableContentFocusSync' when content offset changes due to in-progress zooming.
                //
                c.UpdateContentZoomFocusY();
            }

            if (c.ContentOffsetYChanged != null)
            {
                //
                // Raise an event to let users of the control know that the content offset has changed.
                //
                c.ContentOffsetYChanged(c, EventArgs.Empty);
            }

            if (!c.disableScrollOffsetSync && c.scrollOwner != null)
            {
                //
                // Notify the owning ScrollViewer that the scrollbar offsets should be updated.
                //
                c.scrollOwner.InvalidateScrollInfo();
            }
        }
Пример #2
0
        private static object Zoom_Coerce(DependencyObject d, object baseValue)
        {
            ScrollBox c     = (ScrollBox)d;
            double    value = (double)baseValue;

            value = Math.Min(Math.Max(value, c.MinimumZoom), c.MaximumZoom);
            return(value);
        }
Пример #3
0
        private static void Zoom_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ScrollBox c = (ScrollBox)o;

            if (c.contentScaleTransform != null)
            {
                //
                // Update the content scale transform whenever 'Zoom' changes.
                //
                c.contentScaleTransform.ScaleX = c.Zoom;
                c.contentScaleTransform.ScaleY = c.Zoom;
            }

            //
            // Update the size of the viewport in content coordinates.
            //
            c.UpdateContentViewportSize();

            if (c.enableContentOffsetUpdateFromScale)
            {
                try
                {
                    //
                    // Disable content focus syncronization.  We are about to update content offset whilst zooming
                    // to ensure that the viewport is focused on our desired content focus point.  Setting this
                    // to 'true' stops the automatic update of the content focus when content offset changes.
                    //
                    c.disableContentFocusSync = true;

                    //
                    // Whilst zooming in or out keep the content offset up-to-date so that the viewport is always
                    // focused on the content focus point (and also so that the content focus is locked to the
                    // viewport focus point - this is how the google maps style zooming works).
                    //
                    double viewportOffsetX = c.ViewportZoomFocusX - (c.ViewportWidth / 2);
                    double viewportOffsetY = c.ViewportZoomFocusY - (c.ViewportHeight / 2);
                    double contentOffsetX  = viewportOffsetX / c.Zoom;
                    double contentOffsetY  = viewportOffsetY / c.Zoom;
                    c.ContentOffsetX = (c.ContentZoomFocusX - (c.ContentViewportWidth / 2)) - contentOffsetX;
                    c.ContentOffsetY = (c.ContentZoomFocusY - (c.ContentViewportHeight / 2)) - contentOffsetY;
                }
                finally
                {
                    c.disableContentFocusSync = false;
                }
            }

            if (c.ZoomChanged != null)
            {
                c.ZoomChanged(c, EventArgs.Empty);
            }

            if (c.scrollOwner != null)
            {
                c.scrollOwner.InvalidateScrollInfo();
            }
        }
Пример #4
0
        private static object ContentOffsetY_Coerce(DependencyObject d, object baseValue)
        {
            ScrollBox c          = (ScrollBox)d;
            double    value      = (double)baseValue;
            double    minOffsetY = 0.0;
            double    maxOffsetY = Math.Max(0.0, c.unScaledExtent.Height - c.constrainedContentViewportHeight);

            value = Math.Min(Math.Max(value, minOffsetY), maxOffsetY);
            return(value);
        }
Пример #5
0
        private static void MinOrMaximumZoom_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ScrollBox c = (ScrollBox)o;

            c.Zoom = Math.Min(Math.Max(c.Zoom, c.MinimumZoom), c.MaximumZoom);
        }