TheDeveloper
TheDeveloper

Reputation: 1217

Xamarin forms: Multiple navigation patterns in the same app

Can we have multiple navigation patterns in a single app?

In my app.xaml page I added a function

void SetUpNavigation()
        {
            var page = FreshPageModelResolver.ResolvePageModel<LaunchPageModel>();
            var navPage = new FreshNavigationContainer(page);
            MainPage = navPage;
        }

But after a user signs in I want to use master detail page. Is there a way to do that ??

Upvotes: 0

Views: 623

Answers (1)

Joehl
Joehl

Reputation: 3701

Yes. You just have to set the MainPage of your app again. In our projects, we use a helper class which have a method Restart with following logic:

public static void Restart(View view, NavigationType navtype)
{
    // Reset the mainpage depending on the navigation type
    if (navtype == NavigationType.RestartWithMasterPage)
    {
        Application.Current.MainPage = new MasterPage(view);
    }
    else if (navtype == NavigationType.Restart)
    {
        Application.Current.MainPage = new NavigationPage(view);
    }
    else
    {
        // Just show the page
        Application.Current.MainPage = view;
    }
}

The NavigationType is an enum:

public enum NavigationType
{
    Normal,
    Restart,
    RestartWithMasterPage
}

Upvotes: 2

Related Questions