xamlxamarinxamarin.formscontent-pages

PushAsync not working with ContentPage


Trying to navigate from one page to another page by using

await Navigation.PushAsync(new Page2());

But getting,

System.InvalidOperationException: PushAsync is not supported globally on Android, please use a NavigationPage.

new NavigationPage(new Page2());

And

MainPage = new NavigationPage(new App6.Views.SplashPage());

Also not working


Solution

  • Your Application.MainPage page should be a NavigationPage in order to support PushAsync navigation method.

    Example:

    // In App.cs
    MainPage = new NavigationPage(new MyContentPage());
    
    // Elsewhere in your solution with respect to corner cases
    await Navigation.PushAsync(new MyContentPage2);
    

    Official documentation has nice examples and a good read.