Themelis
Themelis

Reputation: 4255

Get Windows 10 Text Scaling value in WPF

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

enter image description here

Upvotes: 0

Views: 779

Answers (2)

Themelis
Themelis

Reputation: 4255

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");`

Upvotes: 1

mm8
mm8

Reputation: 169400

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;

Upvotes: 2

Related Questions