Hello,
Welcome to our Microsoft Q&A platform!
how to navigate back to a top-level page (one contained in the main TabBar) from a modal page that is not in the main hierarchy
Try to store the route of the 'top-level page' before navigating to the modal page and then go back to the 'top-level page' using Shell.Current.GoToAsync(route)
command. You could the Properties dictionary of App class to save the route value.
Check the code:
public partial class HomePage : ContentPage
{
string className;
public HomePage()
{
InitializeComponent();
className = this.GetType().Name;
}
private void Button_Clicked(object sender, EventArgs e)
{
Application.Current.Properties["top_route"] = className;
Navigation.PushModalAsync(new ModalPage_1());
}
}
public partial class ModalPage_1 : ContentPage
{
public ModalPage_1()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushModalAsync(new ModalPage_2());
}
}
public partial class ModalPage_2 : ContentPage
{
public ModalPage_2()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
var top_route = Application.Current.Properties["top_route"] as string;
Shell.Current.GoToAsync("//" + top_route);
}
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
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.