Two Nearly Same Event Methods Act Differently

I am having very strange behavior in my application. I have two methods:

public void OnItemLoaded(object source, ItemArgs e)
{
    System.Diagnostics.Debug.WriteLine("Event triggered");
    NavigationPage newPage = new NavigationPage(new UrlView());
    Navigation.PushModalAsync(newPage);
}

void Handle_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
{
    NavigationPage newPage = new NavigationPage(new UrlView());
    Navigation.PushModalAsync(newPage);
}

      

The first one is triggered by an event and it works because the WriteLine is displayed correctly but does not move around the page. The second one is just a test for me, it is triggered by clicking on the list item and loaded as expected. They are on the same page and nothing is different from how they work. If I use:

Application.Current.MainPage = new NavigationPage(new UrlView());

It works, but I lose the ability to go back to the previous page by clicking the back button and modal behavior. I thought about using:

Navigation.InsertPageBefore(new TabsPage(), this);

The page loads, but then I get:

"Exception: before it should be in the pushed stack of the current context"

I am thinking about manually inserting the back button on the screen, but that seems pointless ...

I am totally stuck with this. Any idea?

Many thanks.

+3


source to share





All Articles