From Login page to main page?

Hi!

I'm new to the xamarin forms in visual studio. I'm trying to create an app with a login. And this app show should show a lot of info getting from a service..

The question is how to do this? I mean moving from the login page to the next?
What kind of page or something should I be using?
You don't want to get back to the login page unless you logout, because on a mobile app you do that rarely.

I've seen some code where the view.xaml.cs creates the next view but I don't think that is the way to go?

I have created a view which is the login and a vm handling all this. My views are in xaml.

Is possible to do with a factory pattern or something?

Best Answer

Answers

  • TorbenKruseTorbenKruse DEMember ✭✭✭

    The most common way to do this is to push the login page modal on the navigation stack and pop it when you logged in.

  • FuriousFurious USMember

    Thanks for the the reply @TorbenKruse !
    hmm.. I think I get the principle but I have a hard time doing it in the code... could you show it somehow?

    In my app class do this:
    MainPage = new NavigationPage(new LoginView());

    I have a command in my viewmodel(button command) which is binded to the view.. and in this command its logging in, and from here I want to navigate to the next page. How do I do that due to Navigation.PushAsync cannot be called here?

    Should I do another approach or something? A simple example of what I'm looking for would be appreciated!

  • rohitasthanarohitasthana USMember

    I have used login page to Main page controller . -you can take a look in my open source https://github.com/asthanarht/CPXamarin

  • FuriousFurious USMember

    Thanks guys this really helped me out!

    In my method where I log in, I change the mainpage as you said, but I needed it to have it like this to work:

    Device.BeginInvokeOnMainThread(() => App.Current.MainPage = new NavigationPage(new HomePageView()));

Sign In or Register to comment.