Forum Xamarin.Forms

Navigation BUG? OnAppearing() vs PopAsync() ?????

VaylandtVaylandt RUMember ✭✭

protected override void OnAppearing() - when the page is supposed to come from?

Elementary experiment shows: OnBackBtn1push, OnBackBtn2 push, look myCurPage variable points to page2
But should show at page1

This is a bug, or it should be?

page1
{ 
    protected override void OnAppearing() 
        { 
        var myCurPage = Navigation.NavigationStack.LastOrDefault(); 
        }
    public void OnBackBtn1()
        { 
        Navigation.PushAsync(new page2());
        }
}



page2 
{ 
    public void OnBackBtn2()
        { 
        Navigation.PopAsync();
        }
}

Answers

  • JohnHardmanJohnHardman GBUniversity admin

    @Vaylandt - What happens if you await the async methods?

  • VaylandtVaylandt RUMember ✭✭

    @JohnHardman said:
    @Vaylandt - What happens if you await the async methods?

    page2 
    { 
        async void OnBackBtn2(object sender, EventArgs e)
            { 
            await Navigation.PopAsync();
            }
    }
    

    I tried, and so and so, the result is the same.

  • JohnHardmanJohnHardman GBUniversity admin

    @Vaylandt - I've just added your line:

        var myCurPage = Navigation.NavigationStack.LastOrDefault();
    

    into my OnAppearing() and then checked in the debugger what myCurPage is set to. Whether pushing new pages or popping existing pages, myCurPage contains the expected page (i.e. the one that is becoming visible). I tested on Win 8.1 RT and also called base.OnAppearing(); from my OnAppearing.

    What platform are you testing on, and what version of XF are you using?

    It would also help if you could post more of the code, particularly what is calling your OnBackBtn methods, but ideally the full classes for page1 and page2.

Sign In or Register to comment.