Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wieslawsoltes/PanAndZoom
Pan and zoom control for Avalonia.
https://github.com/wieslawsoltes/PanAndZoom
avalonia avaloniaui c-sharp control gui multi-platform pan pan-and-zoom xaml zoom
Last synced: about 1 month ago
JSON representation
Pan and zoom control for Avalonia.
- Host: GitHub
- URL: https://github.com/wieslawsoltes/PanAndZoom
- Owner: wieslawsoltes
- License: mit
- Created: 2016-02-16T23:49:29.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-22T20:47:49.000Z (5 months ago)
- Last Synced: 2024-10-30T01:02:35.518Z (about 2 months ago)
- Topics: avalonia, avaloniaui, c-sharp, control, gui, multi-platform, pan, pan-and-zoom, xaml, zoom
- Language: C#
- Homepage: http://wieslawsoltes.github.io/PanAndZoom/
- Size: 260 MB
- Stars: 345
- Watchers: 10
- Forks: 45
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.TXT
Awesome Lists containing this project
- awesome-avalonia - PanAndZoom - Pan and zoom control for WPF and Avalonia. (Libraries & Extensions / Controls)
README
# 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
## 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` feedYou 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).