Reputation: 4255
How can I programmatically retrieve text scaling value of Windows in WPF?
Upvotes: 0
Views: 779
Reputation: 4255
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
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