Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10 Mobile - cannot hide status bar (StatusBar doesn't exist in context)

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

like image 363
kubci98 Avatar asked Jul 23 '15 17:07

kubci98


1 Answers

The trick is that you have to add a reference to the Microsoft Mobile Extension SDK first. Then the code is the following:

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

The reference can be added by right clicking the universal project. Select "Add reference". In the Reference Manager dialog select "Windows Universal" on the left. Choose "Extensions" and check the "Microsoft Mobile Extension SDK...".

Select the Extension SDK in the Reference Manager

As this is a universal App it will run on every device, but the API will be available only on mobile Devices (aka Phones) with Windows 10. Therefore feature-detect if this API is available at runtime 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 available. (E.g. Method IsTypePresent() . I recommend working with typeof instead of Strings here, e.g. like this:

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

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

like image 137
Daniel Meixner Avatar answered Oct 12 '22 04:10

Daniel Meixner