Alex
Alex

Reputation: 15

Hide status bar on screen rotation

Is it possible to hide the status bar on screen rotation events in Windows Phone 8.1?

Upvotes: 1

Views: 218

Answers (1)

Kristian Vukusic
Kristian Vukusic

Reputation: 3324

The following code shows the status bar on Portrait orientation, and hides it on Landscape orientation.

First you need to subscribe to the ApplicationView.VisibleBoundsChanged event. You can do this for example in your App.xaml.cs constructor:

ApplicationView.GetForCurrentView().VisibleBoundsChanged += OnVisibleBoundsChanged;

You hide the status bar with the StatusBar.GetForCurrentView() instance.

OnVisibleBoundsChanged method:

private async void OnVisibleBoundsChanged(ApplicationView sender, object args)
{
    var currentView = ApplicationView.GetForCurrentView();
    if (currentView.Orientation == ApplicationViewOrientation.Portrait)
    {
        await StatusBar.GetForCurrentView().ShowAsync();
    }
    else if (currentView.Orientation == ApplicationViewOrientation.Landscape)
    {
        await StatusBar.GetForCurrentView().HideAsync();
    }
}

Upvotes: 1

Related Questions