ARH
ARH

Reputation: 1716

Hide status bar in UWP

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!

Upvotes: 7

Views: 6751

Answers (5)

Stefan Over
Stefan Over

Reputation: 6046

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();
    }
}

Upvotes: 10

sich
sich

Reputation: 630

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.

Upvotes: 2

Flack90
Flack90

Reputation: 9

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

Upvotes: 0

Pedro Pombeiro
Pedro Pombeiro

Reputation: 1652

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?

Upvotes: 1

Vitali
Vitali

Reputation: 51

You have to use FullName instead of ToString():

...
ApiInformation.IsTypePresent(typeof(StatusBar).FullName);
...

Upvotes: 2

Related Questions