0

How can I programmatically retrieve text scaling value of Windows in WPF?

enter image description here

Themelis
  • 4,048
  • 2
  • 21
  • 45
  • 1
    Why do you need to get it? Shouldn't WPF take care of it for you? https://stackoverflow.com/questions/9373260/detect-windows-font-size-100-125-and-150 – gunr2171 Aug 18 '21 at 12:20
  • I need this value @gunr2171, I believe it's possible in UWP, unfortunatelly I need it for WPF and I can't find a way to get it. – Themelis Aug 18 '21 at 12:30

2 Answers2

2

Depending on whether you target .NET 5 or an earlier version, you should either set the TargetFramework to net5.0-windows10.0.* or install the Microsoft.Windows.SDK.Contracts NuGet package as described here.

You can then use the Windows.UI.ViewManagement.UISettings.TextScaleFactor property:

double factor = new UISettings().TextScaleFactor;
mm8
  • 163,881
  • 10
  • 57
  • 88
1

Windows 10

I've found a way to retrieve the Text Scaling Factor, without installing any Nuget packages. The idea is to obtain the value directly from the registry.

var userKey = Microsoft.Win32.Registry.CurrentUser;
var softKey = userKey.OpenSubKey("Software");
var micKey = softKey.OpenSubKey("Microsoft");
var accKey = micKey.OpenSubKey("Accessibility");

var factor = accKey.GetValue("TextScaleFactor");`
Themelis
  • 4,048
  • 2
  • 21
  • 45