A great WPF custom control for zooming and panning


Ashley Davis has build a great WPF custom control for zooming and panning. His sample code and control source code has published on CodeProject.com.

The following is his introduction section:


This article examines the use and implementation of a reusable WPF custom control that is used to zoom and pan its content. The article and the sample code show how to use the control from XAML and from C# code.

The main class, ZoomAndPanControl, is derived from the WPF ContentControl class. This means that the primary purpose of the control is to display content. In XAML content controls are wrapped around other UI elements. For example the content might be an image, a map or a chart. In this article I use a Canvas as the content. This Canvas contains some colored rectangles that can be dragged about by the user.

I'll present this article in two parts. The first part shows how to use ZoomAndPanControl and has walkthroughs of the three sample projects. This should be enough if all you want to do is use the code or just try it out. The second part of the article goes into detail as to how the control is implemented. This part will be useful if you want to make your own modifications to ZoomAndPanControl or generally to help you understand how to develop a non-trivial custom control.

The picture also from his web page:

Please read full article here