0
votes

I would like my app to show a Login page, then a MasterDetail page with a 'hamburger' menu. On the hamburger menu I want a Log Out entry that closes the Master Detail and shows the Login page again. I have all but the log out part working.

I have copied code from the MvvmCross Playgrounds sample, specifically the MixedNavFirstPage (which fakes a login procedure), MixedNavMasterDetailPage (the 'hamburger menu'), and MixedNavMasterRootContentPage.

If I try to close the MixedNavMasterDetailPage with await _navigationService.Close(this) then I get a null reference exception in MvxFormsPagePresenter.CloseMasterDetailPage()

This question How to Exit (or Navigate out of )a MasterDetail page to a simple ContentPage in Xamarin. Forms? covers what I want to do in straight Xamarin.Forms, I'm just not sure how to do the equivalent in MvvmCross.

1
I just tried _navigationService.Navigate(typeof(LoginViewModel))- where LoginViewModel is my equivalent of the Playground's MixedNavFirstPage - and that seemed to work in that I got my login page again. But... on logging in a second time I don't get the master detail page again, just a blank page.PaulD
After reading c.lamont.dev's answer confirming I was on the right track I tried again with the Navigate(typeof(LoginViewModel)) and it seemed to work. Perhaps another example of unreliable VS Mac/Android interaction?PaulD

1 Answers

1
votes

In your LoginPage add the MvxContentPagePresentation attribute NoHistory = true

Then simply navigate to the login page, and when the user has logged in, navigate to your MasterDetail page also with NoHistory = true.

When the user logs out again, simply navigate to your LoginPage, and as the NoHistory = true the MasterDetail will be removed completely.

[MvxContentPagePresentation(WrapInNavigationPage = false, NoHistory = true)]
public partial class LoginPage : MvxContentPage<LoginViewModel>
{
    public LoginPage()
    {
        InitializeComponent();
    }
}