Azmarel
Azmarel

Reputation: 1

Windows 10 assigned access (kiosk mode) screen scale DPI

I have an Xamarin UWP application created for assigned access (Kiosk mode). Now on a new screen the default scaling is set to 150%, my app is looking good on 100%. Has someone found a way to change the default scaling of the created kiosk user?

Tried to change the DPI settings using registry edition without luck.

Upvotes: -1

Views: 444

Answers (1)

Junjie Zhu - MSFT
Junjie Zhu - MSFT

Reputation: 2979

UWP does not have API to set the scale in the app directly. But UWP can get the current scale of the system with DisplayInformation, so we can modify the size of the control according to the current scale size.

You can refer to the official sample DpiScaling. The following is a solution based on the sample. The Button control maintains the same size under different scales by controlling the Button's property FontSize .

    private double oldRawPixelsPerViewPixel;
    public MainPage()
    {
        this.InitializeComponent();

        DisplayInformation displayInformation = DisplayInformation.GetForCurrentView();
        displayInformation.DpiChanged += DisplayInformation_DpiChanged;

        oldRawPixelsPerViewPixel = 1.0; // your app is looking good on 100%.
        button.FontSize= PxFromPt(20); //default fontsize
    }

    private void ResetOutput()
    {
        DisplayInformation displayInformation = DisplayInformation.GetForCurrentView();
        double rawPixelsPerViewPixel = displayInformation.RawPixelsPerViewPixel;

        double fontSizeInViewPx = button.FontSize / (rawPixelsPerViewPixel / oldRawPixelsPerViewPixel);
        button.FontSize = fontSizeInViewPx;

        oldRawPixelsPerViewPixel = rawPixelsPerViewPixel;
    }

    private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        ResetOutput();
    }
    private void DisplayInformation_DpiChanged(DisplayInformation sender, object args)
    {
        ResetOutput();
    }

    // Helpers to convert between points and pixels.
    double PtFromPx(double pixel)
    {
        return pixel * 72 / 96;
    }

    double PxFromPt(double pt)
    {
        return pt * 96 / 72;
    }

Upvotes: 0

Related Questions