Need help with PanAndZoom?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

wieslawsoltes
176 Stars 25 Forks MIT License 667 Commits 0 Opened issues

Description

Pan and zoom control for Avalonia.

Services available

!
?

Need anything else?

Contributors list

# 25,996
C#
avaloni...
avaloni...
c-sharp
651 commits

PanAndZoom

Gitter

Build status

NuGet NuGet MyGet

PanAndZoom control for Avalonia

NuGet

PanAndZoom is delivered as a NuGet package.

You can find the NuGet packages here for Avalonia 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

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>("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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.