Josh
Josh

Reputation: 307

Using Xamarin Forms, How can I change page without displaying a navigation bar?

I want to change pages in Xamarin Forms, to do this I have read that you need to use a NavigationPage as the root page. My problem is I can't get rid of the navigation bar at the top. I have tried using SetHasNavigationBar but it doesnt seem to work

public App ()
{
    NavigationPage mypage = new NavigationPage (new PageOne ());
    NavigationPage.SetHasNavigationBar (mypage, false);
    MainPage = mypage;
}

Result: http://i870.photobucket.com/albums/ab261/j0sht/prob_zps4bmxtyvb.png

As you can see from the image, there is still a bar at the top with an icon

Thanks

Upvotes: 5

Views: 5687

Answers (2)

Quark Soup
Quark Soup

Reputation: 4733

In addition to the solution by codechinchilla, you can also achieve the same result in XAML with an attached property:

<ContentPage x:Class="MyComapany.MyProduct.Forms.Views.MyView"
             NavigationPage.HasNavigationBar="False"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns="http://xamarin.com/schemas/2014/forms">

Upvotes: 0

woot
woot

Reputation: 2139

I believe you have to call NavigationPage.SetHasNavigationBar () on the inner page, not the NavigationPage (mypage in your case) try doing the following:

var pageOne = new PageOne();
NavigationPage.SetHasNavigationBar (pageOne, false);
NavigationPage mypage = new NavigationPage (pageOne);
MainPage = mypage;

Edit with how to eliminate nav bar from loading screen on Android (basically set a dummy splash page with simple image background, and redirect to your real main activity on load (at which point Xamarin Forms takes over):

[Activity(MainLauncher = true, NoHistory = true, Theme = "@style/Theme.Splash",
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class SplashScreen : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        var intent = new Intent(this, typeof(MainActivity));
        StartActivity(intent);
    }
}

and the Theme for the splash screen:

<style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@drawable/splashscreen</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>
</style>

Upvotes: 5

Related Questions