How to prevent WPF from scaling with the Windows font size options?

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.


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...


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":

enter image description here

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.

Tags:

Wpf

Highdpi