Click or drag to resize

ZoomPanel Class

ZoomPanel control enables zooming and panning the content of the control with a mouse, with touch and multi-touch gestures.
Inheritance Hierarchy

Namespace:  Ab2d.Controls
Assembly:  Ab2d.Controls.ZoomPanel (in Ab2d.Controls.ZoomPanel.dll) Version: 5.2.6631.1040
Syntax
C#
public class ZoomPanel : ContentControl, IScrollInfo

The ZoomPanel type exposes the following members.

Constructors
  NameDescription
Public methodZoomPanel
Initializes a new instance of the ZoomPanel class.
Top
Properties
  NameDescription
Public propertyActualContentBounds
Gets the Bounds of the contents of a ZoomPanel after the transformation were applied to it.
Public propertyActualViewbox
Gets the Rect that describes the area of the content that is actually visible on the screen.
Public propertyAnimationDuration
Duration of zoom change animation. Default value is 200 milliseconds.
Public propertyCanHorizontallyScroll
IScrollInfo.CanHorizontallyScroll
Public propertyCanVerticallyScroll
IScrollInfo.CanVerticallyScroll
Public propertyCenterPosition
Gets or sets the position that specifies which point of the content will be positioned in the center of the ZoomPanel. The value is in the units (Absolute / Relative) specified by the CenterPositionUnits property.
Public propertyCenterPositionUnits
Gets or sets units in which the CenterPosition is specified. Default value is Relative.
Public propertyStatic memberChangeZoomModeCommand
ChangeZoomModeCommand
Public propertyExtentHeight
IScrollInfo.ExtentHeight
Public propertyExtentWidth
IScrollInfo.ExtentWidth
Public propertyHistoryItems
Provides access to the collection of history items and methods to navigate the history.
Public propertyHorizontalOffset
IScrollInfo.HorizontalOffset
Public propertyIsAnimated
If True than zoom changes are animated. Default value is true.
Public propertyIsCustomContent
Gets a value that indicates if ZoomPanel is currently in custom content mode.
Public propertyIsHistoryEnabled
Gets or sets a boolean that specifies if ZoomPanel is saving history of the previous Viewbox and RotationAngle values. Default value is false.
Public propertyIsMouseWheelZoomEnabled
Gets or sets if zooming with mouse wheel is enabled or disabled. Default value is true (enabled).
Public propertyIsPanningAnimated
If true than also mouse panning is animated, if false mouse panning has immediate effect. Default value is false.
Public propertyIsToggleZoomModeEnabled
Gets or sets if zoom mode toggling is enabled. If true than when setting zoom mode once again to the current zoom mode, the zoom mode goes to None. This is useful for ZoomControllers when for example clicking for the first time on Move button sets the ZoomMode to Move. Clicking on Move button again disables Move mode - goes to None ZoomMode. Default value is true (enabled).
Public propertyIsTouchEnabled
Gets or sets a boolean that specifies if touch and multi-touch control is enabled. Default value is true.
Public propertyIsTouchMoveEnabled
Gets or sets a boolean that specifies if moving with touch is enabled. Default value is true. NOTE: Touch controls work only with .Net 4 build of ZoomPanel (or newer).
Public propertyIsTouchRotateEnabled
Gets or sets a boolean that specifies if rotating with multi-touch is enabled. Default value is true. NOTE: Touch controls work only with .Net 4 build of ZoomPanel (or newer).
Public propertyIsTouchScaleEnabled
Gets or sets a boolean that specifies if scaling with multi-touch pinch is enabled. Default value is true. NOTE: Touch controls work only with .Net 4 build of ZoomPanel (or newer).
Public propertyIsViewboxLimited
Gets or sets a Boolean value that specifies if ViewboxLimits is used to limit the ZoomPanel.
Public propertyIsZoomPositionPreserved
Gets or sets a Boolean that specifies if the position of the point where zooming in or out occurs is preserved. If false than zooming is also centering the zooming point. Default value is true.
Public propertyStatic memberLicenseInfo
License information
Public propertyMouseWheelZoomFactor
Gets or sets the zoom factor that is applied to mouse wheel zooming. The value must be bigger or equal than 1. This value is used for zoom in factor. The zoom out factor is calculated in GetZoomOutFactor method as 1 / zoom factor (can be overridden in derived class).
Public propertyStatic memberMoveDownCommand
MoveDownCommand
Public propertyStatic memberMoveLeftCommand
MoveLeftCommand
Public propertyStatic memberMoveRightCommand
MoveRightCommand
Public propertyStatic memberMoveUpCommand
MoveUpCommand
Public propertyRectangleFill
Fill Brush of the Rectangle used in Rectangle ZoomMode. Default value is #46AAAAFF - semi-transparent light blue.
Public propertyRectangleStroke
Stroke of the Rectangle used in Rectangle ZoomMode. Default value is Blue.
Public propertyStatic memberResetCommand
ResetCommand
Public propertyStatic memberResetToLimitsCommand
ResetToLimitsCommand
Public propertyRotationAngle
Gets or sets the rotation angle in degrees, that determines the angle with witch the content of the ZoomPanel is rotated around the center of the ZoomPanel.
Public propertyScrollLineSizeInPercent
Size in percent of the line when scrolling with ScrollViewer. The size is used when the bottom, up, left or right arrow on scroll slider is clicked. When scrolling with mouse wheel, the line size is multiplied with the value of scroll wheel settings from Control Panel. For example 0.1 scrolls the content of ZoomPanel by 10%.
Public propertyScrollOwner
IScrollInfo.ScrollOwner
Public propertyStatic memberSetMoveModeCommand
SetMoveModeCommand
Public propertyStatic memberSetNoneZoomModeCommand
SetNoneZoomModeCommand
Public propertyStatic memberSetRectangleModeCommand
SetRectangleModeCommand
Public propertyStatic memberSetZoomInModeCommand
SetZoomInModeCommand
Public propertyStatic memberSetZoomOutModeCommand
SetZoomOutModeCommand
Public propertyStretch
Gets or sets the ZoomPanel System.Windows.Media.Stretch mode, which determines how content fits into the available space.
Public propertyUsedViewboxEx
Gets the ViewboxEx control that is used to show the content of ZoomPanel.
Public propertyUseLowQualityBitmapScalingModeWhenAnimating
Gets or sets a Boolean that specifies if LowQuality BitmapScalingMode is used when animating zooming. After zooming is complete the BitmapScalingMode is set to the previous quality setting. This mode works only when the Image is an immediate child of ZoomPanel. By default this property is set to false (using HighQuality mode) except in case WPF is running on lower tier hardware (RenderCapability.Tier is less that 2).
Public propertyVerticalOffset
IScrollInfo.VerticalOffset
Public propertyViewbox
Gets or sets the current viewbox as Rect used to determine which part of ZoomPanel's content is shown.
Public propertyViewboxLimits
Gets or sets the System.Rect that limits the maximum Viewbox size used by ZoomPanel - the maximum zoom out level.
Public propertyViewboxMinSize
Gets or sets the System.Size that limits the Viewbox minimum size used by ZoomPanel - the maximum zoom in level.
Public propertyViewportHeight
IScrollInfo.ViewportHeight
Public propertyViewportWidth
IScrollInfo.ViewportWidth
Public propertyZoomFactor
Gets or sets the zoom factor that defines how much the content of the ZoomPanel is scaled (1 - no scale; >1 - zoom in; <1 - zoom out).
Public propertyZoomInOutFactor
Gets or sets the zoom in and out factor for ZoomIn and ZoomOut mode. The value must be bigger or equal than 1. This value is used for zoom in factor. The zoom out factor is calculated in GetZoomOutFactor method as 1 / zoom factor (can be overridden in derived class).
Public propertyZoomMode
Gets or sets the current zoom mode of the ZoomPanel.
Top
Methods
  NameDescription
Public methodCode exampleCalculateVisibleArea
Calculates the visible area that would be shown if ZoomPanel.Viewbox would be (0,0,1,1).
Public methodFitToHeight
Sets the zoom and translation to show the whole height of the ZoomPanel's content.
Public methodFitToLimitsHeight
Sets the zoom and translation to show the whole limits height of the ZoomPanel's content.
Public methodFitToLimitsWidth
Sets the zoom and translation to show the whole limits width of the ZoomPanel's content (if ZoomPanel is Limited)
Public methodFitToWidth
Sets the zoom and translation to show the whole width of the ZoomPanel's content.
Public methodGetCenterPosition
Returns center positions as Point in the specified units (relative or absolute) and from the specified viewbox.
Public methodGetContentSize
Gets the size of the ZoomPanel's content.
Public methodGetViewboxFromCenterAndZoomFactor
Returns viewbox as Rect from the specified centerPosition, its units and zoomFactor.
Public methodGetZoomFactor
Returns the zoom factor from the specified viewbox as Rect. The method can be overridden to provide custom zoom factor calculations - for example exponential.
Public methodLineDown
IScrollInfo.LineDown
Public methodLineLeft
IScrollInfo.LineLeft
Public methodLineRight
IScrollInfo.LineRight
Public methodLineUp
IScrollInfo.LineUp
Public methodMakeVisible
IScrollInfo.MakeVisible
Public methodMouseWheelDown
IScrollInfo.MouseWheelDown
Public methodMouseWheelLeft
IScrollInfo.MouseWheelLeft
Public methodMouseWheelRight
IScrollInfo.MouseWheelRight
Public methodMouseWheelUp
IScrollInfo.MouseWheelUp
Public methodOnApplyTemplate
OnApplyTemplate
(Overrides FrameworkElementOnApplyTemplate.)
Public methodPageDown
IScrollInfo.PageDown
Public methodPageLeft
IScrollInfo.PageLeft
Public methodPageRight
IScrollInfo.PageRight
Public methodPageUp
IScrollInfo.PageUp
Public methodRefresh
Forces the ZoomPanel to immediately recalculate the visible area based on the current Viewbox settings.
Public methodCode exampleRegisterCustomContentProvider
Registers the ZoomPanel control to show custom content. With custom content the ZoomPanel does not apply scale and translate transform to its content but instead calls the customContentProvider delegate that returns the custom content based on the current zoom parameters.
Public methodReset
Resets the zoom and translation to show the whole content of ZoomPanel (Viewbox="0 0 1 1"). The method also resets the RotationAngle to 0.
Public methodResetNow
Immediately resets the zoom and translation to show the whole content of ZoomPanel (Viewbox="0 0 1 1"). The method also resets the RotationAngle to 0.
Public methodResetToLimits
Resets the zoom and translation to show the content of ZoomPanel based on the ViewboxLimits. If Viewbox is not limited (IsViewboxLimited == false), the method is the same as Reset method. The method also resets the RotationAngle to 0.
Public methodResetToLimitsNow
Resets the zoom and translation to show the whole content of ZoomPanel. The method also resets the RotationAngle to 0.
Public methodSetHorizontalOffset
IScrollInfo.SetHorizontalOffset
Public methodSetVerticalOffset
IScrollInfo.SetVerticalOffset
Public methodSetViewbox
Sets the viewbox relative to the ZoomPanel content.
Public methodSetViewboxNow
Immediately sets the viewbox relative to the ZoomPanel content.
Public methodSetZoom(Double)
Sets the zoom area to the currently set CenterPosition and the zoomFactor parameter. If IsAnimated property is true, the zoom area change is animated.
Public methodSetZoom(Point)
Sets the zoom area to centerPosition parameter (in the current CenterPositionUnits) and the currently set ZoomFactor. If IsAnimated property is true, the zoom area change is animated.
Public methodCode exampleSetZoom(Rect)
Sets the zoom area to the new viewbox. If IsAnimated property is true, the zoom area change is animated.
Public methodSetZoom(Point, Double)
Sets the zoom area to centerPosition parameter (in the current CenterPositionUnits) and the zoomFactor parameter. If IsAnimated property is true, the zoom area change is animated.
Public methodSetZoom(Rect, Double)
Sets the zoom area to the new viewbox. If IsAnimated property is true, the zoom area change is animated.
Public methodSetZoom(Point, ZoomPanelCenterPositionUnitsType, Double)
Sets the zoom area based on centerPosition, units and zoomFactor parameters. If IsAnimated property is true, the viewbox change is animated.
Public methodSetZoom(Point, ZoomPanelCenterPositionUnitsType, Double, Double)
Sets the zoom area based on centerPosition, units and zoomFactor parameters. If IsAnimated property is true, the viewbox change is animated.
Public methodSetZoom(Point, ZoomPanelCenterPositionUnitsType, Double, Double, Boolean, Boolean)
Sets the zoom from the centerPosition and zoomFactor.
Public methodSetZoomNow(Double)
Sets the zoom area to the currently set CenterPosition and the zoomFactor parameter. The zoom area is changed immediately regardless of the IsAnimated property.
Public methodSetZoomNow(Point)
Sets the zoom area to centerPosition parameter (in the current CenterPositionUnits) and the currently set ZoomFactor. The zoom area is changed immediately regardless of the IsAnimated property.
Public methodCode exampleSetZoomNow(Rect)
Sets the zoom area to the new viewbox. The zoom area is changed immediately regardless of the IsAnimated property.
Public methodSetZoomNow(Point, Double)
Sets the zoom area to centerPosition parameter (in the current CenterPositionUnits) and the zoomFactor parameter. The zoom area is changed immediately regardless of the IsAnimated property.
Public methodSetZoomNow(Rect, Double)
Sets the zoom area to the new viewbox. If IsAnimated property is true, the zoom area change is animated.
Public methodSetZoomNow(Point, ZoomPanelCenterPositionUnitsType, Double)
Sets the zoom area based on centerPosition, units and zoomFactor parameters. The zoom area is changed immediately regardless of the IsAnimated property.
Public methodSetZoomNow(Point, ZoomPanelCenterPositionUnitsType, Double, Double)
Sets the zoom area based on centerPosition, units and zoomFactor parameters. The zoom area is changed immediately regardless of the IsAnimated property.
Public methodTranslate
Translates the content by the dx and dy (in absolute units)
Public methodTranslateNow
Translates the content by the dx and dy (in absolute units).
Public methodTranslateRelative
Translates the content by the dx and dy (in relative units: 1 is the whole width/height of ZoomPanel)
Public methodTranslateToCenter
Translates the content of ZoomPanel so that the mouseNewCenterPoint is shown in the center of ZoomPanel.
Public methodTranslateToCenterRelative
Translates the content of ZoomPanel so that the mouseNewCenterPoint is shown in the center of ZoomPanel. newRelativeCenterPoint is in relative coordinates - (0.5, 0.5) is the center of ZoomPanel
Public methodUnregisterCustomContentProvider
Unregisters the ZoomPanel control from custom content provider - from now on the ZoomPanel will use ViewboxEx to apply scale and translate transforms to its content
Public methodZoomAndTranslateToCenter
Zooms and translates the content of ZoomPanel so that the mouseNewCenterPoint is shown in the center of ZoomPanel. mouseNewCenterPoint is in absolute units.
Public methodZoomAndTranslateToCenterRelative
Zooms and translates the content of ZoomPanel so that the mouseNewCenterPoint is shown in the center of ZoomPanel. newRelativeCenterPoint is in relative coordinates - (0.5, 0.5) is the center of ZoomPanel
Public methodZoomAtMousePosition
Zooms the content of ZoomPanel so that the mousePosition stays at the same location.
Public methodZoomAtRelativeMousePosition
Zooms the content of ZoomPanel so that the mousePosition stays at the same location. relativeMousePosition is in relative coordinates - (0.5, 0.5) is the center of ZoomPanel.
Public methodZoomForFactor
Zooms the scene for the zoomFactor. For example zoom factor 2 means that the currently shown scene is scaled for factor 2 (for 100%).
Public methodZoomForRectangle(Rect)
Zooms and translates to show the content defined by newZoomRectangle (coordinates absolute units - from ZoomPanel's position and its ActualWidth and ActualHeight)
Public methodZoomForRectangle(Point, Point)
Zooms and translates to show the content defined by startPoint and endPoint (coordinates in absolute units - from ZoomPanel's position and its ActualWidth and ActualHeight)
Public methodZoomForRectangleRelative
Zooms and translates to show the content defined by newZoomRectangle (coordinates in relative units - 1,1 is right bottom corner or ZoomPanel)
Public methodZoomToFactor
Zooms the scene to the zoomFactor regardless of the current zoomFactor. For example zoomFactor 2 shows app. 50% of the content, 4 shows 25% of the content.
Top
Events
  NameDescription
Public eventPreviewViewboxChanged
PreviewViewboxChanged occurs before the Viewbox or RotationAngle is changed. The event can be used to prevent the change of viewbox or RotationAngle (set Handled property to true), or change the new viewbox or RotationAngle before the change is applied.
Public eventViewboxAnimationCompleted
ViewboxAnimationCompleted occurs after the animation that changed the Viewbox is completed (if Viewbox change was not animated, this event is not fired).
Public eventViewboxAnimationStarted
ViewboxAnimationStarted occurs after when the animation that change the Viewbox is started (if Viewbox change is not animated, this event is not fired).
Public eventViewboxChanged
ViewboxChanged occurs after the Viewbox value is changed. If the zooming is animated the event fires when the animation begins - the NewValue is not the current Viewbox value but the final value when the animation will be completed.
Public eventZoomModeChanged
ZoomModeChanged occurs when ZoomMode is changed
Top
Fields
  NameDescription
Public fieldStatic memberAnimationDurationProperty
AnimationDurationProperty
Public fieldStatic memberIsAnimatedProperty
IsAnimatedProperty
Public fieldStatic memberIsMouseWheelZoomEnabledProperty
IsMouseWheelZoomEnabledProperty
Public fieldStatic memberIsPanningAnimatedProperty
IsPanningAnimatedProperty
Public fieldStatic memberIsToggleZoomModeEnabledProperty
IsToggleZoomModeEnabledProperty
Public fieldStatic memberIsTouchEnabledProperty
IsTouchEnabledProperty
Public fieldStatic memberIsTouchMoveEnabledProperty
IsTouchMoveEnabledProperty
Public fieldStatic memberIsTouchRotateEnabledProperty
IsTouchRotateEnabledProperty
Public fieldStatic memberIsTouchScaleEnabledProperty
IsTouchScaleEnabledProperty
Public fieldStatic memberIsViewboxLimitedProperty
IsViewboxLimitedProperty
Public fieldStatic memberIsZoomPositionPreservedProperty
IsZoomPositionPreserved
Public fieldStatic memberMouseWheelZoomFactorProperty
MouseWheelZoomFactorProperty
Public fieldStatic memberPreviewViewboxChangedEvent
PreviewViewboxChangedEvent RoutedEvent
Public fieldStatic memberRectangleFillProperty
RectangleFillProperty
Public fieldStatic memberRectangleStrokeProperty
RectangleStrokeProperty
Public fieldStatic memberRotationAngleProperty
RotationAngleProperty
Public fieldStatic memberStretchProperty
StretchProperty
Public fieldStatic memberViewboxAnimationCompletedEvent
ViewboxAnimationCompletedEvent RoutedEvent
Public fieldStatic memberViewboxAnimationStartedEvent
ViewboxAnimationStartedEvent RoutedEvent
Public fieldStatic memberViewboxChangedEvent
ViewboxChangedEvent RoutedEvent
Public fieldStatic memberViewboxLimitsProperty
ViewboxLimitsProperty
Public fieldStatic memberViewboxMinSizeProperty
ViewboxMinSizeProperty
Public fieldStatic memberZoomFactorProperty
ZoomFactorProperty
Public fieldStatic memberZoomInOutFactorProperty
ZoomInOutFactorProperty
Public fieldStatic memberZoomModeChangedEvent
ZoomModeChangedEvent RoutedEvent
Public fieldCode exampleZoomPanelAnimator
Gets or sets a class that is used to animate the ZoomPanel. Default value is ZoomPanelQuinticAnimator that adds some easing to animation.
Top
Remarks

ZoomPanel control can be used to simply add a powerful and animated zooming and panning to any WPF application. The control can be used to zoom and pan bitmap images, vector graphics, UI Elements, etc.

Content can be zoomed and panned with mouse, with touch and multi-touch gestures. Touch support can be enabled or disabled with IsTouchEnabled, IsTouchMoveEnabled, IsTouchScaleEnabled and IsTouchRotateEnabled properties. By default all properties are set to true.

NOTE that touch controls are working only in .Net 4 build of ZoomPanel (or newer) and does not work in .Net 3.5 build of the library.

The following image shows the ZoomPanel with ZoomController in the upper left corner, ZoomPanelNavigator in the upper left corner and ZoomPanelMiniMap in the bottom right corner:

ZoomPanel is usually used with a ZoomController that sets the mode in which ZoomPanel works. The following ZoomPanel modes are supported: None, Move, Rectangle, ZoomIn, ZoomOut (see ZoomPanelZoomModeType for more info). The current zoom mode can be get or set with ZoomMode property.

With using ZoomPanelNavigator it is possible to set the zoom factor with a slider and move around the visible area with buttons.

The ZoomPanelMiniMap shows which part of the content is shown. It can be used to preview which part of the content is shown. It also enables moving the shown content and zooming in and out with mouse wheel (shown in the bottom right corner of the image above).

By default the content of the ZoomPanel can be freely zoomed in and out and panned to any direction. But it is possible to limit this by ViewboxLimits, ViewboxMinSize and IsViewboxLimited. The ViewboxLimits sets the maximum Viewbox size used by ZoomPanel - maximum zoom out level. The ViewboxMinSize sets the minimum Viewbox size used by ZoomPanel - maximum zoom in level.

To add scrollbars to the ZoomPanel simply add it inside ScrollViewer control and set the CanContentScroll property on ScrollViewer to True (see the sample below). The ZoomPanel implements the IScrollInfo interface. Therefore it can be fully controlled by the scrollbars. The size and position of the scrollbars is determined by the currently shown area.

By default the zooming in and out is animated using quintic function to ease the animation. The default animation is implemented in ZoomPanelQuinticAnimator class. It is possible to provide custom animations with deriving a class from BaseZoomPanelAnimator and setting its instance to the ZoomPanelAnimator property.

ZoomPanel also has a lot of methods that can be used to modify the ZoomPanel from code-behind. See samples for more info.

With calling RegisterCustomContentProvider it is also possible to zoom dynamic and custom content - the content that is based on the current zoom level - for example a map.

Examples

The following sample shows how to use the ZoomPanel and ZoomController:

<Window x:Class="Ab2d.ZoomControlSample.ZoomPanelSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ab2d="clr-namespace:Ab2d.Controls;assembly=Ab2d.Controls.ZoomPanel">
  <Grid>
      <ScrollViewer CanContentScroll="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
          <ab2d:ZoomPanel Name="myZoomPanel" Viewbox="0.2 0.2 0.6 0.6" IsAnimated="True" AnimationDuration="0:0:0.5"
                          ViewboxLimits="-0.1 -0.1 1.2 1.2" ViewboxMinSize="0.1 0.1" IsViewboxLimited="True">
              <TextBlock>12345</TextBlock>
          </ab2d:ZoomPanel>
      </ScrollViewer>  
      <ab2d:ZoomController VerticalAlignment="Top" 
                           HorizontalAlignment="Right"/>
      <ab2d:ZoomPanelNavigator VerticalAlignment="Top" 
                               HorizontalAlignment="Left"/>
      <ab2d:ZoomPanelMiniMap VerticalAlignment="Bottom" 
                             HorizontalAlignment="Right"/>
    </Grid>
</Window>
Note that a namespace definition (ab2d) need to be added to the Window. Also note that the ZoomController automatically discovers the ZoomPanel. If ZoomPanel is not found or more than one ZoomPanel exist in the Window, than use the TargetZoomPanel or TargetZoomPanelName property on ZoomController.

The following code is used to zoom the content of myZoomPanel for factor 1.5 (for 50%):

myZoomPanel.ZoomForFactor(1.5);

See Also