I don't want my WPF GUI to scale with Windows font size options (DPI). It's not just a matter of specifying a fixed font size on the UserControl because scaling affects images and borders in the UserControl. Is there a property that I can set on the UserControl to turn off scalling? If not, how can I do that?
-
4Resolution independence is one of core ideas of WPF. Turning it off is not a good idea, especially if it would affect only part of your UI. DPI range practically used on various computers will only increase, displays with huge pixel densities are already on the way. – Matěj Zábský May 02 '11 at 12:58
-
2Generally speaking I agree with you. But in this case I really need to turn scaling off because this UserControl is hosted in an existing Windows Forms application where scaling is not implemented. The result is that I have parts of the app with big fonts and parts of the app with fixed fonts. Supporting the Windows fonts setting in the rest of the Windows Forms app is not viable for now. – Sylvain May 02 '11 at 13:41
-
1I guess that makes sense, +1 then. – Matěj Zábský May 02 '11 at 14:05
-
I have exactly the same issue. Hybrid apps are an issue, especially under tablets. – John Fairbanks Feb 28 '19 at 20:07
3 Answers
You could scale down your UserControl based on the current DPI setting. For example, if you wrapped your UserControl with the following DpiDecorator, then it should look the same regardless of the DPI setting:
public class DpiDecorator : Decorator {
public DpiDecorator() {
this.Loaded += (s, e) => {
Matrix m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
ScaleTransform dpiTransform = new ScaleTransform(1 / m.M11, 1 / m.M22);
if (dpiTransform.CanFreeze)
dpiTransform.Freeze();
this.LayoutTransform = dpiTransform;
};
}
}
Or you could move that logic to your UserControl.
The code to obtain the DPI scale factor was from this blog post.

- 2,609
- 2
- 33
- 38

- 40,753
- 6
- 122
- 148
Windows includes a compatibility helper for buggy applications that fail under high-dpi settings:
Be sure to leave off (or turn off) "Use Windows XP style DPI scaling":
And be sure your application does not have a "dpiAware
" entry in its assembly manifest.
Windows will lie to your application, tell it that it's 96dpi, and then the graphics card will scale the entire window up for you.
Everything will be slightly fuzzy, and generally unpleasant to use, but it will work well enough until you can fix the buggy WinForm control.
Note: The
dpiAware
manifest entry lets your application tell Windows that it wants to opt-out of the dpi-scaling. Applications only add this item if they've been tested at high-dpi.

- 246,734
- 253
- 869
- 1,219
in addition the the DpiDecorator, you will also need to fix the font size of your items. For example, in Windows XP, if your setting is set to Large Fonts, Menu Item font size is set to 14 and is also scaled up using the DPI setting, so if you don't fix your MenuItem font size or any other UI item font, you will get Window's default value for this item type. Also remember that a user can manually change the font size/font face for other items...

- 599
- 4
- 9