Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UseLayoutRounding and High DPI in WPF

Tags:

dpi

wpf

Our WPF application, using .NET 4.5, has UseLayoutRounding on by default at the root level of each window. On Windows 7 and Windows 8, our application looks good at 100% and 125% DPI settings. However, once we bump it up to 150%, we start having issues with double thick border lines throughout the product. If we turn UseLayoutRounding off at 150%, suddenly controls and borders look much better. We're investigating having this setting be dynamically set based on the DPI.

What I'm trying to understand is how a monitor's physical DPI plays into this. Could I expect that a 1080p monitor with a higher than normal DPI would not exhibit this kind of problem? If I ran my app on a Surface Pro (which we unfortunately don't have) with 200% DPI scaling turned on, would I see the same issues?

I guess what baffles me is that UseLayoutRounding does exactly what we want it to do when it comes to lining up adjacent borders and shapes at 100% and 125%, but then the opposite is true at 150%. Does anyone have any insights here?

like image 362
Sean Beanland Avatar asked Mar 14 '14 13:03

Sean Beanland


People also ask

Is WPF DPI aware?

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

What is high DPI override scaling?

DPI-scaling overrides This forces the process to run in per-monitor DPI awareness mode. This setting was previously referred to as “Disable display scaling on high-DPI settings.” This setting effectively tells Windows not to bitmap stretch UI from the exe in question when the DPI changes.

How do you override DPI and scaling?

Select Display > Change the size of text, apps, and other items, and then adjust the slider for each monitor. Right-click the application, select Properties, select the Compatibility tab, and then select the Disable display scaling on high DPI settings check box.


1 Answers

WPF released a fix for clipping in Visuals on high DPI. In order to get this behavior on an app targeting TFV < 4.6, you need at to add the following in the runtime section of your app.config file :

<AppContextSwitchOverrides value="Switch.MS.Internal.DoNotApplyLayoutRoundingToMarginsAndBorderThickness=false;" />

Note: This will only work on a machine which has atleast .NET 4.6 installed. If your app targets framework version >= 4.6, then you don't even need to put this switch and should get the good behavior by default.

like image 146
rohit21agrawal Avatar answered Sep 21 '22 15:09

rohit21agrawal