PushAsync is not supported globally on Android, please use a NavigationPage - Xamarin.Forms
Asked 07 September, 2021
Viewed 556 times
  • 56
Votes

I have the following method in an Xamarin.Forms.ContentPage wired to a button click event

public class LoginPage : ContentPage
{
    private Button _loginButton = null;
    private Entry _PasswordInput = null;
    private Entry _UsernameInput = null;

    public LoginPage()
    {
        _UsernameInput = new Entry { Placeholder = "Username" };
        _PasswordInput = new Entry { Placeholder = "Password", IsPassword = true };

        _loginButton = new Button
        {
            Text = "Login",
            BorderRadius = 5
        }

        _loginButton.Clicked += LogIn;

        Content = new StackLayout 
        {
            VerticalOptions = LayoutOptions.Center,
            Children = 
            {
                 _UsernameInput, _PasswordInput, _loginButton, 
            },
            Spacing = 15
        };
    }

    public async void LogIn(object sender, EventArgs eventsArgs)
    {
        //do authenticate stuff here
        SSO.MyAuthentication client = new SSO.MyAuthentication();

        bool isAuthenticated = client.Authenticate(_UsernameInput.Text, _PasswordInput.Text);

        if(isAuthenticated)
        {
             //Push home page to top of navigation stack
             Navigation.PushAsync(new HomePage());
        }
    }
}

On the following line of code Navigation.PushAsync(new HomePage());, I am getting the following exception while debugging:


  

PushAsync is not supported globally on Android, please use a NavigationPage

How do I resolve this issue using a Xamarin.Forms.NavigationPage object?

9 Answer