In This Article

Input Bindings

The ZoomContentControl supports interactive zooming and panning through the use of input bindings. This topic covers the default behavior, as well as how to customize the behavior.

Mouse Gestures

The Windows Presentation Framework (WPF) includes support for defining input bindings on controls, through the InputBindings collection. This collection defines various gestures, which, when executed, will raise an associated command.

There are two native WPF gestures that can be used: MouseGesture and KeyboardGesture. MouseGesture encompasses actions like clicking (and double-clicking) mouse buttons, while KeyboardGesture captures pressing keys. Both types support modifier keys, such as Ctrl, Shift, etc. This tells the gesture that the specified modifier key must be pressed when the gesture is performed for the associated command to be fired. For example, when using MouseAction.LeftClick with a modifier key of ModifierKeys.Control, then the associated command is only fired when the user clicks the left mouse button while holding down the Ctrl key.

The Shared Library adds an additional gesture that can bind mouse wheel actions to a command. MouseWheelGesture supports positive or negative changes (i.e., up or down scrolling of the mouse wheel), and can also be used with the ZoomContentControl.

There are several helper types that make defining a gesture easier via XAML, which include KeyboardBinding, MouseBinding, and MouseWheelBinding. Using these classes, the Gesture property can be set to a simple string value. For example, setting the MouseBinding.Gesture property to "Control+LeftClick" will automatically create the appropriate MouseGesture.

Default Mouse Behavior

The ZoomContentControl includes several default input bindings that use MouseGesture and MouseWheelGesture with one of the commands defined by ZoomContentControlCommands.

The following table lists the default MouseGesture bindings and their associated command.

Gesture Command
Left Click StartPanDrag
Ctrl+Left Click StartZoomIn
Ctrl+Shift+Left Click StartZoomOut
Shift+Left Click StartPanDrag

The following table lists the default MouseWheelGesture bindings and their associated command.

Gesture Command
Positive Delta LineUp
Negative Delta LineDown
Shift+Positive Delta LineLeft
Shift+Negative Delta LineRight
Ctrl+Positive Delta ZoomInToPoint
Ctrl+Negative Delta ZoomOutFromPoint
Ctrl+Shift+Positive Delta ZoomInToPoint
Ctrl+Shift+Negative Delta ZoomOutFromPoint

The default input bindings can be disabled by setting AreDefaultInputBindingsEnabled to false. This allows the InputBindings to be completely customized from XAML.

Mouse Cursor

The ZoomContentControl will automatically update its Cursor property based on the specified input bindings. Specifically, it looks for an input binding that uses a MouseGesture with a MouseAction.LeftClick action and specifies modifier keys that match the current key state. For example, if the Ctrl key is currently pressed, then it will search for a MouseGesture with a MouseAction.LeftClick action and with ModifierKeys.Control defined.

If an input binding is found that matches the current state, then the cursor will be updated based on the specified command. The following table lists the commands and their associated cursor.

Command Cursor
CenterAndZoomInToPoint Screenshot
CenterAndZoomOutFromPoint Screenshot
CenterToPoint Screenshot
ResetView None
StartPanDrag Screenshot and Screenshot
StartZoomDrag Screenshot
StartZoomIn Screenshot
StartZoomOut Screenshot
StartZoomToRegion Screenshot
ZoomIn Screenshot
ZoomInToPoint Screenshot
ZoomOut Screenshot
ZoomOutFromPoint Screenshot
ZoomToFit None

The mouse cursor can be customized as needed by overriding the UpdateCursor method.