Windows 10 Mobile - cannot hide the status bar (StatusBar does not exist in context)

I am trying to hide the status bar in my Windows 10 Universal App. In WP 8.1, I used StatusBar.GetForCurrentView().HideAsync(); to hide the status bar, however this will not work in my current project (Monogame, Win10 UAP). I get the error “StatusBar not found in current context” (yes, I'm using Windows.UI.ViewManagement). Am I doing something wrong or has this option removed the StatusBar? How do I do this in the W10M? Thanks in advance.

+7
windows statusbar
source share
1 answer

The trick is to first add a link to the Microsoft Mobile Extension SDK. Then the code looks like this:

 StatusBar statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView(); await statusBar.HideAsync(); 

The link can be added by right-clicking on the universal project. Select "Add Link." In the Link Manager dialog box, select Windows Universal on the left. Select "Extensions" and check the "Microsoft Mobile Extension SDK ...".

Select the extension SDK in the link manager

Since this is a universal application, it will work on every device, but the API will be available only on mobile devices (aka Phones) with Windows 10. Therefore, the function detects whether this API is available at run time before you actually call the API. Otherwise, it will throw a TypeLoadException at runtime.

Use the Windows.Foundation.Metadata.ApiInformation namespace to find out if the API is accessible. (For example, the IsTypePresent () method. I recommend working with typeof instead of Strings here, e.g. for example:

 var isStatusBarPresent = ApiInformation.IsTypePresent(typeof(StatusBar).ToString()); 

You can learn more about adaptive code here: https://channel9.msdn.com/Series/A-Developers-Guide-to-Windows-10/08

+20
source share

All Articles