WPF enables the application developer to apply arbitrary transforms to every UI element. This can be used to create dynamically scalable/zoomable UIs, enabling the end-user to scale the user interface of the application.
Pulling off a dynamically scalable/zoomable UI is prohibitively difficult (and thus practically impossible) to do in classic Win32 (and by extension - WinForms) and DHTML as well as other popular GUI toolkits such as AWT, Swing, QT, etc. It is, however, remarkably easy to do in WPF. Here’s how:
1. First, you need to give to the user a way to control the scale factor. A Slider control is the natural choice for that
ToolTip="Determines the UI scale factor."
Value="1" Minimum="0.1" Maximum="4"
2. Next, define a LayoutTransform for the FrameworkElement you intend to scale (this is typically the top-level panel that contains all of your UI). The LayoutTransform needs to be a ScaleTransform.
3. Bind the scale factor of the ScaleTransform to the value of the slider control.
<DockPanel Grid.Column="0" Grid.ColumnSpan="2" LastChildFill="True">
4. Finally, provide a way for the user to reset the scaling factor back to 1 or 100%. One way to do that is to do that is to define a double-click handler for your Scale control, which resets the scale factor:
void RestoreScalingFactor(object sender, MouseButtonEventArgs args)
((Slider)sender).Value = 1.0;
Here are the results:
Note that because of the use of LayoutTransform, the original layout of the window is preserved. All of elements of the UI are within reach and completely usable regardless of the current scale factor.
Several existing WPF applications (e.g. Microsoft Expression Blend) already expose such UI scaling capability. Some use the mouse wheel to control the scale factor.
Here’s one possible strategy of using the mouse-wheel. Let’s assume the following UI contract:
CTRL + Wheel up
Scale up (i.e. zoom in)
CTRL + Wheel down
Scale down (i.e. zoom out)
CTRL + Wheel click
Restore scaling factor to 100%
We just intercept the appropriate events in the OnPreviewMouseWheel and OnPreviewMouseDown methods of the main window as follows:
protected override void OnPreviewMouseWheel(MouseWheelEventArgs args)
if (Keyboard.IsKeyDown(Key.LeftCtrl) ||
uiScaleSlider.Value += (args.Delta > 0) ? 0.1 : -0.1;
protected override void OnPreviewMouseDown(MouseButtonEventArgs args)
if (args.MiddleButton == MouseButtonState.Pressed)