PushAsync is not supported globally on Android, please use a NavigationPage - Xamarin.Forms

前端 未结 9 1464
情歌与酒
情歌与酒 2020-12-12 17:34

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

public class Lo         


        
相关标签:
9条回答
  • 2020-12-12 18:18

    I only change pushAsync with pushModalAsync :)

    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());
               Navigation.PushModalAsync(new HomePage());
        }
    }
    
    0 讨论(0)
  • 2020-12-12 18:20

    Verify that the previous page is not using a PushModalAsync. If later you use a PushAsync, you will have the error "PushAsync is not supported globally on Android, please use a NavigationPage."

    0 讨论(0)
  • 2020-12-12 18:26

    You are calling "PushAsync":

    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }
    
        private void btnCourseList_Clicked(object sender, EventArgs e)
        {
            Navigation.PushAsync(new PageB());
        }
    }
    

    but you did not start the NavigationPage, which normally is done in the App.cs class, or at least it should be started before any call to "PushAsync":

    MainPage = new NavigationPage(new PageA());
    
    0 讨论(0)
  • 2020-12-12 18:27

    In app.xaml.cs file,

    Replace

     MainPage = new <namespace>.MainPage();
    

    With

     MainPage = new NavigationPage(new <namespace>.MainPage());
    

    Then Use

     await Navigation.PushAsync(new NavigationPage(new MainPage2()));
    
    0 讨论(0)
  • 2020-12-12 18:29

    You need to enclose your LoginPage in a NavigationPage. This will fix your error, but will leave you with the LoginPage contained on your navigation stack.

    An alternate approach would be to make your HomePage the root of the application, then display the LoginPage modally on top of it. Only when the user successfully logs in do you dismiss the LoginPage modal so they can see the HomePage.

    0 讨论(0)
  • 2020-12-12 18:31

    I got one problem mixing Rg.Plugins.Popup and ZXin.Net.Mobile Scanner.

    Calling the scanner inside a popup was triggering this same error. PushModalAsync solved the error, but the popup was over the scan so easy solution was make the popup invisible until the scanner was on.

        private async void FrmQrCode_Tapped(object sender, EventArgs e)
        {
            ZXingScannerPage scanPage = new ZXingScannerPage();
            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;
                ZXing.BarcodeFormat barcodeFormat = result.BarcodeFormat;
                string type = barcodeFormat.ToString();
                Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PopModalAsync();
    
                    this.IsVisible = true;
    
                    Token = result.Text.Trim();
                });
            };
            this.IsVisible = false;
            await Navigation.PushModalAsync(scanPage);
        }
    
    0 讨论(0)
提交回复
热议问题