# PanAndZoom [![Gitter](https://badges.gitter.im/wieslawsoltes/PanAndZoom.svg)](https://gitter.im/wieslawsoltes/PanAndZoom?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Build Status](https://dev.azure.com/wieslawsoltes/GitHub/_apis/build/status/wieslawsoltes.PanAndZoom?branchName=master)](https://dev.azure.com/wieslawsoltes/GitHub/_build/latest?definitionId=98&branchName=master) [![CI](https://github.com/wieslawsoltes/PanAndZoom/actions/workflows/build.yml/badge.svg)](https://github.com/wieslawsoltes/PanAndZoom/actions/workflows/build.yml) [![NuGet](https://img.shields.io/nuget/v/Avalonia.Controls.PanAndZoom.svg)](https://www.nuget.org/packages/Avalonia.Controls.PanAndZoom) [![NuGet](https://img.shields.io/nuget/dt/Avalonia.Controls.PanAndZoom.svg)](https://www.nuget.org/packages/Avalonia.Controls.PanAndZoom) [![MyGet](https://img.shields.io/myget/panandzoom-nightly/vpre/Avalonia.Controls.PanAndZoom.svg?label=myget)](https://www.myget.org/gallery/panandzoom-nightly) PanAndZoom control for Avalonia ![](images/PanAndZoom.png) ## NuGet PanAndZoom is delivered as a NuGet package. You can find the NuGet packages here for [Avalonia](https://www.nuget.org/packages/Avalonia.Controls.PanAndZoom/) or by using nightly build feed: * Add `https://www.myget.org/F/panandzoom-nightly/api/v2` to your package sources * Alternative nightly build feed `https://pkgs.dev.azure.com/wieslawsoltes/GitHub/_packaging/Nightly/nuget/v3/index.json` * Update your package using `PanAndZoom` feed You can install the package for `Avalonia` based projects like this: `Install-Package Avalonia.Controls.PanAndZoom -Pre` ### Package Sources * https://api.nuget.org/v3/index.json * https://www.myget.org/F/panandzoom-nightly/api/v2 ## Resources * [GitHub source code repository.](https://github.com/wieslawsoltes/PanAndZoom) ## Using PanAndZoom `MainWindow.xaml` ```XAML ``` `MainWindow.xaml.cs` ```C# using System.Diagnostics; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.PanAndZoom; using Avalonia.Input; using Avalonia.Markup.Xaml; namespace AvaloniaDemo { public class MainWindow : Window { private readonly ZoomBorder? _zoomBorder; public MainWindow() { this.InitializeComponent(); this.AttachDevTools(); _zoomBorder = this.Find("ZoomBorder"); if (_zoomBorder != null) { _zoomBorder.KeyDown += ZoomBorder_KeyDown; _zoomBorder.ZoomChanged += ZoomBorder_ZoomChanged; } } private void InitializeComponent() { AvaloniaXamlLoader.Load(this); } private void ZoomBorder_KeyDown(object? sender, KeyEventArgs e) { switch (e.Key) { case Key.F: _zoomBorder?.Fill(); break; case Key.U: _zoomBorder?.Uniform(); break; case Key.R: _zoomBorder?.ResetMatrix(); break; case Key.T: _zoomBorder?.ToggleStretchMode(); _zoomBorder?.AutoFit(); break; } } private void ZoomBorder_ZoomChanged(object sender, ZoomChangedEventArgs e) { Debug.WriteLine($"[ZoomChanged] {e.ZoomX} {e.ZoomY} {e.OffsetX} {e.OffsetY}"); } } } ``` ### Getting zoom ratio To get current zoom ratio use `ZoomX` and `ZoomY` properties. ### Getting pan offset To get current pan offset use `OffsetX` and `OffsetY` properties. ### Constrain zoom ratio To constrain zoom ratio use `MinZoomX`, `MaxZoomX`, `MinZoomY` and `MaxZoomY` properties. ### Constrain pan offset To constrain pan offset use `MinOffsetX`, `MaxOffsetX`, `MinOffsetY` and `MaxOffsetY` properties. ### Enable or disable constrains To enable or disable constrains use `EnableConstrains` flag. ## License PanAndZoom is licensed under the [MIT license](LICENSE.TXT).