How will you navigate from one page to another?
How will you navigate from one page to another?
In Xamarin.Forms, you can navigate from one page to another using the NavigationPage
and Navigation
classes.
Here's an example of how you can do it:
// Create a new NavigationPage
var navigationPage = new NavigationPage(new MainPage());
// Push a new page onto the navigation stack
navigationPage.PushAsync(new DetailPage());
// Pop the current page from the navigation stack
navigationPage.PopAsync();
// Push a new page onto the navigation stack and remove the current page
navigationPage.PushAsync(new DetailPage(), true);
In your XAML file, you can use the Navigation.PushAsync
method in the code-behind to navigate to another page:
private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new DetailPage());
}
You can also use the Navigation.PopAsync
method to go back to the previous page:
private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PopAsync();
}
If you want to navigate to a page and remove the current page from the navigation stack, you can use the Navigation.PushAsync
method with the true
parameter:
private async void Button_Clicked(object sender, EventArgs e)
{
await ...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào