Search code examples
c#wpfdpi

Have a WPF Application ignore DPI settings


I have a wpf application that is designed for a 1900x1200 resolution but some of our users have used the windows display settings to resize everything by 125%-150%, is there a way to have an application ignore those settings and still display normally?

I have seen something called SetProcessDPIAware here, but havent had any luck with it.

Here is a screen shot of the application with the display scaling turned up to 150% Application with Scaling

As you can see the application is way too small and there is no way to get it to be correctly sized.


Solution

  • Dpi awareness will not help in this case. It will only change CompositionTarget.TransformToDevice matrix, but controls sizes will not change.

    I use view box to scale all content. All sizes in my app are designed for Surface Pro 3 portrait:

    <Window>
        <Viewbox Stretch="Uniform">
            <Grid Width="1440" Height="2160">
                <!-- ... -->
            </Grid>
        </Viewbox>
    </Window>
    

    You can calculate view box size basing on screen DPI. See this answer: https://stackoverflow.com/a/12414433/991267