Search code examples
c#xamarinxamarin.formsxamarin.ios

C# Xamarin.Forms ios Navigation.PushAsync not working properly


I have xamrin.forms project with both Android and iOS. I have just simple 2 pages where i call one from the other. On android everything is working perfectly as it should but on iOS any call for forms (navigation.PushAsync, DisplayAlert, ...) is not working properly (does nothing) until I put application to the sleep (put it to the background ) and then when I reload it back everything starts to work perfectly.

This is how i create first page in App.xaml.cs

var page = new NavigationPage(new FirstPage());
MainPage = page;

Button command for my first page calls for this:

FormsNavigation.PushAsync(secondPage, true);

I allredy tried to wrap Push into Device.BeginInvokeOnMainThread but no result.


Solution

  • In Xamarin.Forms, when using a NavigationPage to navigate to a ContentPage, use await Navigation.PushAsync.

    And, because all UI animations must be invoked on the Main UI Thread, I recommend wrapping it Device.InvokeOnMainThreadAsync.

    async Task NavigateToSecondPage()
    {
        var secondPage = new SecondPage();
        await Device.InvokeOnMainThreadAsync(() => Navigation.PushAsync(secondPage, true));    
    }