简体   繁体   中英

Get Windows 10 Text Scaling value in WPF

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

在此处输入图像描述

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;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM