7

I have used below code to hide status bar in UWP. When I run the app in development mode in my computer the status bar is not shown in windows phone. I deployed the app in Windows Store, after downloading the app, I see the status bar appears in my app.

Here is my code:

var isAvailable = Windows.Foundation.Metadata.ApiInformation.IsTypePresent(typeof(StatusBar).ToString());
   if (isAvailable)
       hideBar();

async void hideBar()
{
   StatusBar bar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
   await bar.HideAsync();
}

The question is, why the above code shouldn't work in windows store? Also, I have the link to my app App link in windows store, but when i search for exact key word in windows store, my application is not shown in windows store, but clicking in link would appear my app in window store.

Thanks!

ARH
  • 1,566
  • 3
  • 25
  • 56

5 Answers5

10

Checking for the Contract, rather for the type StatusBar works fine for me.

private async Task InitializeUi()
{
    // If we have a phone contract, hide the status bar
    if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1, 0))
    {
        var statusBar = StatusBar.GetForCurrentView();
        await statusBar.HideAsync();
    }
}
Stefan Over
  • 5,851
  • 2
  • 35
  • 61
  • thank you, I have implemented your code and will be looking after deployment to windows store. – ARH Dec 16 '15 at 10:31
  • where do you call this function? In App.xaml.cs? or on the actual pages that you load? – erotavlas Apr 24 '16 at 02:02
  • @erotavlas Depends on your use-case. If you want to hide the status bar during the whole application lifetime, you'd call it in the activate/suspend method. If you want to hide the status bar during a specific page, you'd hide it during the navigate-to/from event handlers. – Stefan Over Apr 24 '16 at 18:34
  • You need to add REFERENCES windows desktop AND mobile extensions for the UWP (this defines the StatusBar varialble). – pollaris Dec 03 '17 at 18:32
2

You have to use FullName instead of ToString():

...
ApiInformation.IsTypePresent(typeof(StatusBar).FullName);
...
Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
Vitali
  • 51
  • 2
2

This code won't work because after .Net Native compilation (which Store does) typeof(StatusBar).ToString() will not return the literal type name as you expect, but will return something like "EETypeRVA:0x00021968". Use literal string instead (you aren't going to rename StatusBar, right? ;) or use IsApiContractPresent or typeof(StatusBar).FullName (as was already advised). P.S. The same issue can be reproduced without publishing, just run it using Release configuration.

sich
  • 505
  • 6
  • 10
1

Could it be that when you compile in Release and with the .NET Native toolchain, the type info gets discarded and so you're not passing the string you think you're passing? Maybe you can try hard-coding the full type name?

Pedro Pombeiro
  • 1,654
  • 13
  • 14
0

In Windows 10 the command is Window.Current.SetTitleBar(null);

Flack90
  • 9
  • 1