Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to set WPF application windows in all screen resolution and DPI scaling and working OS is surface, windows 7, windows 10 and DPI scaling 100 to 500%

What I have tried:

C#
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;
        };
    }
}
Posted
Updated 30-Nov-16 20:24pm
v3
Comments
Kornfeld Eliyahu Peter 1-Dec-16 2:52am    
Not clear why you should play with DPI to create scale-able forms... It is not even clear what do you mean by scale-able...Do you want textboxes scale?
sureshsankar 1-Dec-16 3:37am    
How to fit(not appearing) Window form to screen resolution and DPI 125 to 500%
Philippe Mori 2-Dec-16 11:49am    
One possibility is to design the UI at a fixed size and the zoom the content to fit the available space using a ViewBox.

You might also check the related questions on the sidebar.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900