1

All code works well but after i make account and press login in button I have a problem loading a new page with the side menu. Don't know what to do. I'm new with xamarin forms.

Login.cs

    private  void Button_Clicked_Login(object sender, EventArgs e)
    {
        string dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UserDataBase.db");
        SQLiteConnection db = new SQLiteConnection(dbpath);
        RegistrationTable myquery = db.Table<RegistrationTable>().Where(u => u.Login.Equals(EntryUser.Text) && u.Password.Equals(EntryPassword.Text)).FirstOrDefault();

        if (myquery != null)
        {
            Navigation.PushModalAsync(new NavigationPage(new HomePage()));
        }
        else
        {
            Device.BeginInvokeOnMainThread(async () =>
            {
                bool result = await DisplayAlert("", "", " ", "Cancel");

                if (result)
                {
                    await Navigation.PushModalAsync(new NavigationPage(new LoginPage()));
                }
                else
                {
                    await Navigation.PushModalAsync(new NavigationPage(new LoginPage()));
                }
            });
        }
    }

HomePage is just shell

<Shell.FlyoutHeader>
    <local:HeaderView/>
</Shell.FlyoutHeader>

<FlyoutItem Title="LeftSideMenu"
           Shell.TabBarIsVisible="False"
           FlyoutDisplayOptions="AsMultipleItems">

    <Tab Icon="calculator.png" Title="Calculator">
        <ShellContent ContentTemplate="{DataTemplate local:CalculatorPage}"/>
    </Tab>

</FlyoutItem>
Cfun
  • 8,442
  • 4
  • 30
  • 62

1 Answers1

1

You are not awaiting the call of PushModelAsync() when pushing HomePage, also Button_Clicked_Login() is missing async keyword in it signature.

private  async void Button_Clicked_Login(object sender, EventArgs e)
{
     ...
     await Navigation.PushModalAsync(new NavigationPage(new HomePage()));
     ...
}

Another approach is to have your Shell (that includes login page also) as your initial MainPage, by using bindings to show/hide pages and Shell navigation:

How can you restrict/control the navigation routes the user can visit based on login status/role?

Cfun
  • 8,442
  • 4
  • 30
  • 62