|
<Window x:Class="ZoomAndPanSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ZoomAndPanSample"
xmlns:ZoomAndPan="clr-namespace:ZoomAndPan;assembly=ZoomAndPan"
Title="Main Window"
Height="600"
Width="800"
Loaded="MainWindow_Loaded"
FocusManager.FocusedElement="{Binding ElementName=scroller}"
>
<Window.Resources>
<!-- UI commands. -->
<RoutedUICommand x:Key="Commands.ZoomOut" />
<RoutedUICommand x:Key="Commands.ZoomIn" />
</Window.Resources>
<Window.InputBindings>
<!--
Bind keys to commands.
-->
<KeyBinding
Key="Minus"
Command="{StaticResource Commands.ZoomOut}"
/>
<KeyBinding
Key="Plus"
Command="{StaticResource Commands.ZoomIn}"
/>
</Window.InputBindings>
<Window.CommandBindings>
<!--
Bind commands to event handlers.
-->
<CommandBinding
Command="{StaticResource Commands.ZoomOut}"
Executed="ZoomOut_Executed"
/>
<CommandBinding
Command="{StaticResource Commands.ZoomIn}"
Executed="ZoomIn_Executed"
/>
</Window.CommandBindings>
<!--
Wrap the ZoomAndPanControl in a ScrollViewer.
When the scaled content that is displayed in ZoomAndPanControl is larger than the viewport onto the content
ScrollViewer's scrollbars can be used to manipulate the offset of the viewport.
-->
<ScrollViewer
x:Name="scroller"
CanContentScroll="True"
VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility="Visible"
>
<!--
This is the control that handles zooming and panning.
-->
<ZoomAndPan:ZoomAndPanControl
x:Name="zoomAndPanControl"
Background="LightGray"
MouseDown="zoomAndPanControl_MouseDown"
MouseUp="zoomAndPanControl_MouseUp"
MouseMove="zoomAndPanControl_MouseMove"
MouseWheel="zoomAndPanControl_MouseWheel"
>
<!--
This Canvas is the content that is displayed by the ZoomAndPanControl.
Width and Height determine the size of the content.
-->
<Canvas
x:Name="content"
Width="2000"
Height="2000"
Background="White"
>
<!--
Add some rectangles that the user can drag about.
-->
<Rectangle
Canvas.Left="50"
Canvas.Top="50"
Width="80"
Height="150"
Fill="Blue"
Cursor="Hand"
MouseDown="Rectangle_MouseDown"
MouseUp="Rectangle_MouseUp"
MouseMove="Rectangle_MouseMove"
/>
<Rectangle
Canvas.Left="550"
Canvas.Top="350"
Width="80"
Height="150"
Fill="Green"
Cursor="Hand"
MouseDown="Rectangle_MouseDown"
MouseUp="Rectangle_MouseUp"
MouseMove="Rectangle_MouseMove"
/>
<Rectangle
Canvas.Left="850"
Canvas.Top="850"
Width="30"
Height="20"
Fill="Purple"
Cursor="Hand"
MouseDown="Rectangle_MouseDown"
MouseUp="Rectangle_MouseUp"
MouseMove="Rectangle_MouseMove"
/>
<Rectangle
Canvas.Left="1850"
Canvas.Top="1850"
Width="80"
Height="150"
Fill="Red"
Cursor="Hand"
MouseDown="Rectangle_MouseDown"
MouseUp="Rectangle_MouseUp"
MouseMove="Rectangle_MouseMove"
/>
</Canvas>
</ZoomAndPan:ZoomAndPanControl>
</ScrollViewer>
</Window>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Software craftsman | Author | Writing rapidfullstackdevelopment.com - Posting about how to survive and flourish as a software developer
Follow on Twitter for news and updates: https://twitter.com/codecapers
I'm writing a new book: Rapid Fullstack Development. Learn from my years of experience and become a better developer.
My second book, Bootstrapping Microservices, is a practical and project-based guide to building distributed applications with microservices.
My first book Data Wrangling with JavaScript is a comprehensive overview of working with data in JavaScript.
Data-Forge Notebook is my notebook-style application for data transformation, analysis and transformation in JavaScript.
I have a long history in software development with many years in apps, web apps, backends, serious games, simulations and VR. Making technology work for business is what I do: building bespoke software solutions that span multiple platforms.
I have years of experience managing development teams, preparing technical strategies and creation of software products. I can explain complicated technology to senior management. I have delivered cutting-edge products in fast-paced and high-pressure environments. I know how to focus and prioritize to get the important things done.
Author
- Rapid Fullstack Development
- Bootstrapping Microservices
- Data Wrangling with JavaScript
Creator of Market Wizard
- https://www.market-wizard.com.au/
Creator of Data-Forge and Data-Forge Notebook
- http://www.data-forge-js.com
- http://www.data-forge-notebook.com
Web
- www.codecapers.com.au
Open source
- https://github.com/ashleydavis
- https://github.com/data-forge
- https://github.com/data-forge-notebook
Skills
- Quickly building MVPs for startups
- Understanding how to get the most out of technology for business
- Developing technical strategies
- Management and coaching of teams & projects
- Microservices, devops, mobile and fullstack software development