I inherited a solution that had some code behind to allow zooming the contents of a
Window because the WPF design was for a 2560 x1440 display and was hard to see on a smaller display. I moved the code into a behavior and added the ability to drag the zoomed control. I also designed it so that the container did not have to be just a
Window but could be any
Using the Code
Below is an example of how to use this behavior:
The behavior can only be used on a
Control that derives from a
ContentControl because it depends on the
Content property. In the example, a
ContentControl is used but it will work on a
Window or a
UserControl. Also, for everything to look right, the
Content has to fill the
ContentControl. This is why the
Stretch is set to Fill. You can see what happens the
Content size is different from the
Window at start up.
Initial after zooming in.
After zooming in and dragging as far as possible down and right.
After zooming out (notice the content is centered).
To resize the contents, hold down the keyboard Control key and the scroll button on the mouse. To drag, hold down the Control key and the Left mouse button and drag. When zoomed out, the
Content is centered on the
This is really not a very sophisticated control. It does not include slider controls when the contents are zoomed out, and does not include a way to reset the zoom, or to allow the zoom limits to be changed.
- 08/16/17: Initial version