Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove navigation bar on Xamarin Forms app with Caliburn.Micro

When using the FormsApplication base class with a brand new Xamarin.Forms app using Caliburn.Micro, I end up with an empty navigation bar at the top of my screen. I assume it's being created by Caliburn.Micro somehow, because an out-of-the-box Xamarin.Forms app doesn't have that.

Is there any way I can use Caliburn.Micro with Xamarin.Forms without this navigation bar?

like image 616
Brian Sullivan Avatar asked Apr 15 '16 21:04

Brian Sullivan


4 Answers

I have not used Caliburn.Micro, but I am assuming that it is wrapping your page with a NavigationPage, as what you describe is what would happen if so.

You should be able to hide that navigation bar by setting a simple attribute in your page like so:

<ContentPage NavigationPage.HasNavigationBar="false"
    ..... >
</ContentPage>

If you are not using XAML pages and doing all of your UI in code instead, then you can do it this way within your page constructor:

NavigationPage.SetHasNavigationBar(this, false);
like image 163
Keith Rome Avatar answered Dec 29 '22 09:12

Keith Rome


If you are using a Shell, (if you chose any of Visual Studios three Templates when first creating your project, you probably are) NavigationPage.HasNavigationBar="False" won't work. Try adding this line of code to each of your ContentPages

Shell.NavBarIsVisible="False"
like image 34
Cedric Moore Avatar answered Dec 29 '22 10:12

Cedric Moore


This drove me nuts for a while as every answer I've seen for the code behind is a partial answer.

Lets say in your App.Xaml.cs file you have your NavigationPage constructor set like this:

MainPage = new NavigationPage(new Astronomy.MainPage());

You then have to go into the MainPage code behind and add code to remove the NavBar: you can't add the line to the app constructor.

public MainPage()
    {
        InitializeComponent();
        NavigationPage.SetHasNavigationBar(this, false);
    }

So glad I finally figured this out! It's been causing me a headache for a while!

like image 25
Jason S Avatar answered Dec 29 '22 10:12

Jason S


It works for me:

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
    this.Window.AddFlags(WindowManagerFlags.Fullscreen); // hide the status bar

                // Set our view from the "main" layout resource
    SetContentView(Resource.Layout.Main);

    int uiOptions = (int)Window.DecorView.SystemUiVisibility;

    uiOptions |= (int)SystemUiFlags.LowProfile;
    uiOptions |= (int)SystemUiFlags.Fullscreen;
    uiOptions |= (int)SystemUiFlags.HideNavigation;
    uiOptions |= (int)SystemUiFlags.ImmersiveSticky;

    Window.DecorView.SystemUiVisibility = 
     (StatusBarVisibility)uiOptions;
}
like image 26
Sina Avatar answered Dec 29 '22 10:12

Sina