/// <summary> /// Event raised when the 'ContentOffsetY' property has changed value. /// </summary> private static void ContentOffsetY_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { ZoomPanControl c = (ZoomPanControl)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(); } }
/// <summary> /// Method called to clamp the 'ContentScale' value to its valid range. /// </summary> private static object ContentScale_Coerce(DependencyObject d, object baseValue) { ZoomPanControl c = (ZoomPanControl)d; double value = (double)baseValue; value = Math.Min(Math.Max(value, c.MinContentScale), c.MaxContentScale); return(value); }
/// <summary> /// Event raised when the 'ContentScale' property has changed value. /// </summary> private static void ContentScale_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { ZoomPanControl c = (ZoomPanControl)o; if (c._contentScaleTransform != null) { // // Update the content scale transform whenever 'ContentScale' changes. // c._contentScaleTransform.ScaleX = c.ContentScale; c._contentScaleTransform.ScaleY = c.ContentScale; } // // Update the size of the viewport in content coordinates. // c.UpdateContentViewportSize(); if (c._enableContentOffsetUpdateFromScale) { try { // // Disable content focus synchronization. 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.ContentScale; double contentOffsetY = viewportOffsetY / c.ContentScale; c.ContentOffsetX = (c.ContentZoomFocusX - (c.ContentViewportWidth / 2)) - contentOffsetX; c.ContentOffsetY = (c.ContentZoomFocusY - (c.ContentViewportHeight / 2)) - contentOffsetY; } finally { c._disableContentFocusSync = false; } } if (c.ContentScaleChanged != null) { c.ContentScaleChanged(c, EventArgs.Empty); } if (c._scrollOwner != null) { c._scrollOwner.InvalidateScrollInfo(); } }
/// <summary> /// Method called to clamp the 'ContentOffsetY' value to its valid range. /// </summary> private static object ContentOffsetY_Coerce(DependencyObject d, object baseValue) { ZoomPanControl c = (ZoomPanControl)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); }
/// <summary> /// Method called to clamp the 'ContentOffsetX' value to its valid range. /// </summary> private static object ContentOffsetX_Coerce(DependencyObject d, object baseValue) { ZoomPanControl c = (ZoomPanControl)d; double value = (double)baseValue; double minOffsetX = 0.0; double maxOffsetX = Math.Max(0.0, c.unScaledExtent.Width - c.constrainedContentViewportWidth); value = Math.Min(Math.Max(value, minOffsetX), maxOffsetX); return(value); }
/// <summary> /// Event raised 'MinContentScale' or 'MaxContentScale' has changed. /// </summary> private static void MinOrMaxContentScale_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { ZoomPanControl c = (ZoomPanControl)o; c.ContentScale = Math.Min(Math.Max(c.ContentScale, c.MinContentScale), c.MaxContentScale); }