Hello,
ו have login page which go to main page and later from main page I go to other pages and go back.
You can refer to following steps to navigate your page.
Firstly, if the first page is login page. You can set the loginpage
as the MainPage in App.xaml.cs
like following code.
public App()
{
InitializeComponent();
MainPage =new LoginPage();
}
Then, Open your LoginPage, if you click the login button and navigate to the MainPage, you can use App.Current.MainPage = new NavigationPage(new MainPage());
to redefine the MainPage.
public partial class LoginPage : ContentPage
{
public LoginPage()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
App.Current.MainPage = new NavigationPage(new MainPage());
}
}
Next, you can navigate the page by Navigation.PushAsync
in the MainPage or other navigated pages. For example, I want to navigate to the NewPage2 in the Button click event of the Mainpage. I can use following code to navigate it.
private void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new NewPage2());
}
In the end, you can navigate to the previous page by Navigation.PopAsync();
. For example, If you want to navigate to the MainPage
in the NewPage2
's button click event, you can use following code.
private void Button_Clicked(object sender, EventArgs e)
{
Navigation.PopAsync();
}
Best Regards, Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.