Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My WPF app is per-monitor dpi-aware out of the box. I was not expecting that?

I am a bit confused about per-monitor dpi-aware in WPF. I thought you need to do some work to make your windows scale properly on different monitors (as described in Developing a Per-Monitor DPI-Aware WPF Application).

But I've just ran my app on pc with two monitors (2560x1440 and 2160x1440) and the dialogue would automatically scale itself when I move it between monitors. That's on the latest fast ring Windows 10. Am I missing something?

like image 962
Nick Sologoub Avatar asked Mar 08 '16 10:03

Nick Sologoub


People also ask

Is WPF DPI-aware?

Windows Presentation Foundation (WPF) applications are by default system DPI-aware.

How do I make my application DPI-aware?

To make your application dpi-aware, you must cancel automatic dpi scaling, and then adjust user interface elements to scale appropriately to the system dpi.

What is DPI in WPF?

If the current DPI setting is 96 dpi (dots per inch), the WPF units are equivalent to pixels. I.e. A window specified as 96 units high would appear as 1 inch high. If the DPI setting is different, the specified WPF units are scaled by dpi/96 to get the resulting pixel value.


1 Answers

What you see is an example of System scaling when one app window moves to a different monitor with a different DPI. That is because WPF apps are by-default System DPI Aware. As a result, if you notice carefully, you'll see WPF visuals/text gets blurred when the target DPI is higher or they look fuzzy when the target DPI is lower. Also, note that monitor resolution does not matter for WPF apps, since WPF is device resolution agnostic (it's measurement unit is Device independent Pixels).

Good news : .NET 4.6.2 preview just got released and it hasPer Monitor DPI Awareness out of the box. Check out the developer guide and samples here :

https://github.com/Microsoft/WPF-Samples/tree/master/PerMonitorDPI

like image 123
rohit21agrawal Avatar answered Sep 19 '22 16:09

rohit21agrawal