i want to navigate from a page to an other page

bilel miled 21 Reputation points
2021-02-19T15:41:01.197+00:00

0

i want to navigate from a page(not main page) which is in a tabbed page to a page when clicking on a button. i tried this :

 MainPage = new NavigationPage(new listofinterest());
    MainPage = new  TabbedPageMain()
    {
        BarBackgroundColor = Color.FromHex("#F8F8F8"),

    };

////////

public partial class listofinterest : ContentPage
{
    private async void Add(object sender, EventArgs e)
    {
        await Navigation.PushAsync(new NavigationPage(new MainPage()));
    }
}

it didn't work i get this error "PushAsync is not supported globally on Android, please use a NavigationPage.'" i need help please.
and the first page is the tabbed page this is why i wrote overriding mainpage with tabbedpage

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,295 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,951 Reputation points
    2021-02-20T02:07:15.133+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    i get this error "PushAsync is not supported globally on Android, please use a NavigationPage."

    This is because Navigation.PushAsync method requires to be used in the navigation stack. To avoid this, try using the model page to perform navigation:

       Navigation.PushModalAsync(new NavigationPage(new Page1()));  
    

    Or add the tabbedPage to the navigation stack and set the navigationbar invisible. Then it's available to call Navigation.PushAsync to perform navigation.

       public partial class App : Application  
       {  
           public App()  
           {  
               InitializeComponent();  
         
               MainPage = new NavigationPage( new TabbedPage1());  
           }  
       }  
         
       public partial class TabbedPage1 : TabbedPage  
       {  
           public TabbedPage1()  
           {  
               InitializeComponent();  
         
               NavigationPage.SetHasNavigationBar(this, false);  
           }  
       }  
         
        public partial class listofinterest : ContentPage  
        {  
            private async void Add(object sender, EventArgs e)  
            {  
                await Navigation.PushAsync(new NavigationPage(new MainPage()));  
            }  
        }  
    

    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.


0 additional answers

Sort by: Most helpful