Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Navigation Page + Master Detail Page

$
0
0

Hi all, bit of an odd problem or maybe its just the way i'm trying to solve it. I have a Login page which can branch off to a regular content page (registration page) or a master detail page. The Master Detail page's detail is wrapped in a Navigation Page so that it can access sub menus and go back and forth between them.

This has worked well so far using the LoginPattern example from xamarin samples but is now behaving oddly when adding the regular content page branch to the login page. So far i have only tested on Android and for reference, this is the code i'm using.

App.cs

    public class App
    {
        public static INavigation Navigation { get; set; }
        static IPageManager pageManager;

        public static Page GetMainPage()
        {
            return new MainMenu();
        }

        public static Page GetLoginPage(IPageManager ipm)
        {
            pageManager = ipm;
            return new NavigationPage(new LoginPage(ipm));
        }

        public static void ReturnToLoginPage()
        {
            pageManager.ReturnToLogin();
        }
    }

    public interface IPageManager
    {
        void ReturnToLogin();
        void ShowMainMenu();
    }

Android Main Activity

[Activity(Label = "App Companion", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : AndroidActivity, IPageManager
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Xamarin.Forms.Forms.Init(this, bundle);
            Xamarin.FormsMaps.Init(this, bundle);

            SetPage(App.GetLoginPage(this));
        }

        public void ReturnToLogin()
        {
            SetPage(App.GetLoginPage(this));
        }

        public void ShowMainMenu()
        {
            SetPage(App.GetMainPage());
        }
    }

Currently, from my LoginPage, when i call ShowMainMenu() everything works as expected but if try to open the registration page from the LoginPage using...

Navigation.PushAsync(new RegisterPage());

I get the Global navigation not supported etc... which is fine, so i wrap the RegisterPage in a NavigationPage(). When i do this it then allows me to navigate to the registration page but when try to open the main menu i get an unhandled exception. Normally this would lead me to dig deeper but in this case it doesn't give any info about the exception, there's nothing in logcat and try as i might i can't catch the exception itself.

Has anyone experienced anything similar or any suggestions for a better way to approach this?


Viewing all articles
Browse latest Browse all 58056

Trending Articles