Git Product home page Git Product logo

matrixpanandzoomdemo's Introduction

PanAndZoom

Gitter Build status Build Status

PanAndZoom control for WPF and Avalonia

NuGet

PanAndZoom is delivered as a NuGet package.

You can find the packages here NuGet or by using nightly build feed:

  • Add https://www.myget.org/F/panandzoom-nightly/api/v2 to your package sources
  • Update your package using PanAndZoom feed

You can install the package for Avalonia based projects like this:

Install-Package Avalonia.Controls.PanAndZoom -Pre

You can install the package for WPF based projects like this:

Install-Package Wpf.Controls.PanAndZoom -Pre

Package Dependencies

  • Avalonia
  • System.Reactive
  • System.Reactive.Core
  • System.Reactive.Interfaces
  • System.Reactive.Linq
  • System.Reactive.PlatformServices
  • Serilog
  • Splat
  • Sprache

Package Sources

Resources

Using PanAndZoom

You can also use custom xmlns definition for ZoomBorder control: xmlns:paz="https://github.com/panandzoom".

Avalonia

MainWindow.xaml

<Window x:Class="AvaloniaDemo.MainWindow"
        xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:paz="clr-namespace:Avalonia.Controls.PanAndZoom;assembly=Avalonia.Controls.PanAndZoom"
        UseLayoutRounding="True"
        Title="PanAndZoom Avalonia Demo" Height="640" Width="640">
    <Grid Background="SlateBlue" RowDefinitions="Auto,*,24" ColumnDefinitions="50,*,50">
        <StackPanel Background="#1FFFFFFF" Margin="4" 
                    HorizontalAlignment="Center" VerticalAlignment="Top" 
                    Grid.Row="0" Grid.Column="1">
            <TextBlock Text="E - Extent" Foreground="WhiteSmoke" FontSize="11"/>
            <TextBlock Text="F - Fill" Foreground="WhiteSmoke" FontSize="11"/>
            <TextBlock Text="R - Reset" Foreground="WhiteSmoke" FontSize="11"/>
            <TextBlock Text="T - Toggle AutoFitMode" Foreground="WhiteSmoke" FontSize="11"/>
            <TextBlock Text="Mouse Wheel - Zoom to Point" Foreground="WhiteSmoke" FontSize="11"/>
            <TextBlock Text="Mouse Right Button Down - Pan" Foreground="WhiteSmoke" FontSize="11"/>
        </StackPanel>
        <paz:ZoomBorder Name="zoomBorder" AutoFitMode="None" ZoomSpeed="1.2" 
                        ClipToBounds="True" Background="DarkGray" 
                        VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
                        Grid.Row="1" Grid.Column="1">
            <Canvas Background="LightGray" Width="300" Height="300">
                <Rectangle Canvas.Left="100" Canvas.Top="100" Width="50" Height="50" Fill="Red"/>
            </Canvas>
        </paz:ZoomBorder>
    </Grid>
</Window>

MainWindow.xaml.cs

using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.PanAndZoom;
using Avalonia.Input;
using Avalonia.Markup.Xaml;

namespace AvaloniaDemo
{
    public class MainWindow : Window
    {
        private ZoomBorder zoomBorder;

        public MainWindow()
        {
            this.InitializeComponent();
            this.AttachDevTools();

            zoomBorder = this.Find<ZoomBorder>("zoomBorder");
            zoomBorder.KeyDown += ZoomBorder_KeyDown;
        }

        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);
        }

        private void ZoomBorder_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.E)
            {
                zoomBorder.Extent();
            }

            if (e.Key == Key.F)
            {
                zoomBorder.Fill();
            }

            if (e.Key == Key.R)
            {
                zoomBorder.Reset();
            }

            if (e.Key == Key.T)
            {
                zoomBorder.ToggleAutoFitMode();
                zoomBorder.AutoFit();
            }
        }
    }
}

WPF

MainWindow.xaml

<Window x:Class="WpfDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:paz="clr-namespace:Wpf.Controls.PanAndZoom;assembly=Wpf.Controls.PanAndZoom"
        WindowStartupLocation="CenterScreen"
        UseLayoutRounding="True" SnapsToDevicePixels="True" TextOptions.TextFormattingMode="Display"
        Title="PanAndZoom WPF Demo" Height="640" Width="640">
    <Grid Background="SlateBlue">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="24"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="50"/>
        </Grid.ColumnDefinitions>
        <StackPanel Background="#1FFFFFFF" Margin="4" 
                    HorizontalAlignment="Center" VerticalAlignment="Top" 
                    Grid.Row="0" Grid.Column="1">
            <TextBlock Text="E - Extent" Foreground="WhiteSmoke" FontSize="11"/>
            <TextBlock Text="F - Fill" Foreground="WhiteSmoke" FontSize="11"/>
            <TextBlock Text="R - Reset" Foreground="WhiteSmoke" FontSize="11"/>
            <TextBlock Text="T - Toggle AutoFitMode" Foreground="WhiteSmoke" FontSize="11"/>
            <TextBlock Text="Mouse Wheel - Zoom to Point" Foreground="WhiteSmoke" FontSize="11"/>
            <TextBlock Text="Mouse Right Button Down - Pan" Foreground="WhiteSmoke" FontSize="11"/>
        </StackPanel>
        <paz:ZoomBorder x:Name="zoomBorder" AutoFitMode="None" ZoomSpeed="1.2" ClipToBounds="True" 
                        Background="DarkGray" 
                        VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
                        Grid.Row="1" Grid.Column="1">
            <Canvas Background="LightGray" Width="300" Height="300">
                <Rectangle Canvas.Left="100" Canvas.Top="100" Width="50" Height="50" Fill="Red"/>
            </Canvas>
        </paz:ZoomBorder>
    </Grid>
</Window>

MainWindow.xaml.cs

using System.Windows;
using System.Windows.Input;

namespace WpfDemo
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            zoomBorder.KeyDown += ZoomBorder_KeyDown;
        }

        private void ZoomBorder_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.E)
            {
                zoomBorder.Extent();
            }

            if (e.Key == Key.F)
            {
                zoomBorder.Fill();
            }

            if (e.Key == Key.R)
            {
                zoomBorder.Reset();
            }

            if (e.Key == Key.T)
            {
                zoomBorder.ToggleAutoFitMode();
                zoomBorder.AutoFit();
            }
        }
    }
}

License

PanAndZoom is licensed under the MIT license.

matrixpanandzoomdemo's People

Contributors

wieslawsoltes avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.