[MS] How can I programmatically obtain the value of the “Make text bigger” slider? - devamazonaws.blogspot.com

The XAML UI framework automatically honors the Windows "Make text bigger" setting, but what if you're using some other framework and want to respect the text scale factor?

You can query the value of the "Make text bigger" slider from the Windows.UI.ViewManagement.UISettings.TextScaleFactor property, and then incorporate that value into your font size calculations.¹

// C#
double GetTextScaleFactor()
{
    return (new Windows.UI.
                ViewManagement.UISettings()).TextScaleFactor;
}

// C++/WinRT
#include <winrt/Windows.UI.ViewManagement.h>

double GetTextScaleFactor()
{
    return winrt::Windows::UI::
           ViewManagement::UISettings().TextScaleFactor();
}

// C++/CX

double GetTextScaleFactor()
{
    return (ref new Windows::UI::
        ViewManagement::UISettings())->TextScaleFactor;
}

// C++/WRL
#include <Windows.UI.ViewManagement.h>

HRESULT GetTextScaleFactor(double* value)
{
    *value = 1.0;

    using namespace Microsoft::WRL;
    using namespace Microsoft::WRL::Wrappers;

    ComPtr<IInspectable> instance;
    HRESULT hr = RoActivateInstance(HStringReference(
        RuntimeClass_Windows_UI_ViewManagement_UISettings).Get(),
        &instance);
    if (FAILED(hr)) return hr;

    ComPtr<ABI::Windows::UI::ViewManagement::IUISettings2>
        settings2;
    hr = instance.As(&settings2);
    if (FAILED(hr)) return hr;

    hr = settings2->get_TextScaleFactor(value);
    if (FAILED(hr)) return hr;

    return S_OK;
}

You can also subscribe to the Text­Scale­Factor­Changed event to be notified when the text scale factor changes.

¹ Note that the text scale factor is not a blind scaling applied to all fonts. It generally applies to your main body font, and the scaling applied to other fonts diminishes based on the distance of those other fonts from the body font. For example, chapter headings should not be magnified by as large a factor as body text.


Post Updated on August 30, 2023 at 03:00PM
Thanks for reading
from devamazonaws.blogspot.com

Comments

Popular posts from this blog

Scenarios capability now generally available for Amazon Q in QuickSight - devamazonaws.blogspot.com

Research and Engineering Studio on AWS Version 2024.08 now available - devamazonaws.blogspot.com

Amazon EC2 C6id instances are now available in AWS Europe (Paris) region - devamazonaws.blogspot.com