Interface IViewportState
Mutable viewport state for controlling pan/zoom operations.
Use this interface to programmatically control the viewport, such as centering on elements, fitting to bounds, or implementing custom navigation.
public interface IViewportState : IReadOnlyViewportState, ICoordinateTransformer
- Inherited Members
- Extension Methods
Methods
CenterOn(Point)
Centers the viewport on a specific canvas point.
After this call, the specified canvas point will be at the center of the viewport. Zoom level is not changed.
void CenterOn(Point canvasPoint)
Parameters
canvasPointPointThe point in canvas coordinates to center on.
FitToBounds(Rect, double)
Adjusts zoom and pan to fit the specified canvas bounds within the viewport.
Use this to implement "fit to content" or "zoom to selection" features.
The resulting view will show all of canvasBounds with
the specified padding around the edges.
void FitToBounds(Rect canvasBounds, double padding = 50)
Parameters
canvasBoundsRectThe bounds to fit, in canvas coordinates. Pass the bounding box of all elements you want to show.
paddingdoublePadding in screen pixels to leave around the bounds. Default is 50.
Pan(double, double)
Pans the viewport by the specified delta in screen coordinates.
Positive deltaX moves the view right (canvas moves left). Positive deltaY moves the view down (canvas moves up).
void Pan(double deltaX, double deltaY)
Parameters
deltaXdoublePan amount in X direction (screen pixels).
deltaYdoublePan amount in Y direction (screen pixels).
Reset()
Resets the viewport to default state (zoom = 1.0, centered on origin).
void Reset()
SetOffset(double, double)
Sets the pan offset directly.
void SetOffset(double offsetX, double offsetY)
Parameters
offsetXdoubleNew X offset in screen coordinates.
offsetYdoubleNew Y offset in screen coordinates.
SetZoom(double, Point?)
Sets the zoom level, optionally zooming toward a specific screen point.
When zoomCenter is provided, the canvas point under that
screen position will remain stationary after zooming. This creates a natural
"zoom toward cursor" behavior.
void SetZoom(double zoom, Point? zoomCenter = null)