Search code examples
javascriptuwpwindows-10windows-10-universalwindows-10-mobile

How to show status bar in UWP JavaScript app?


How to show the Windows 10 system status bar on mobile when writing the app in JavaScript? The Windows.​UI.​View​Management.StatusBar class is not available on Mobile, or so says Visual Studio 2017.


Solution

  • You need to add the references to the UWP Mobile Extension, because the status bar only exists on Mobile.

    enter image description here

    Go to Project > Add References.

    Check "Windows Mobile Extension for the UWP" and press "OK".

    WARNING: You need to check if the API is present because the app can crash if it is not. Like this:

    if (Windows.Foundation.Metadata.ApiInformation.isTypePresent("Windows.UI.ViewManagement.StatusBar")) {
    
        let statusbar = Windows.UI.ViewManagement.StatusBar.getForCurrentView();
        statusbar.showAsync();
    
    }