Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms Navigation.PushAsync Not Working

I have a Xamarin.Forms project, and I have a custom control that should open a new page when tapped. Unfortunately, nothing happens when I call Navigation.PushAsync(...);. I've read countless StackOverflow questions (such as this one) and Xamarin Forums threads and done several Google searches, but none of the solutions seem to solve my issue.

  • My control inherits from ContentView, as all Xamarin.Forms views do.
  • src is a custom class that contains some data points that are used by this control and EventDetailsPage.
  • I can confirm that the gesture does work itself, but the call to PushAsync() does nothing.
  • I have tried manipulating the statement in ways so that a NavigationPage is used (such that it becomes myNavigationPage.Navigation.PushAsync(new EventDetailsPage(src));).
  • I have also tried creating a constructor that takes a Page and uses it in away similar to the above point.

My control's constructor:

public EventControl() {
    InitializeComponent();
    GestureRecognizers.Add(new TapGestureRecognizer() {
        Command = new Command(() => Navigation.PushAsync(new EventDetailsPage(src)))
    });
}

Typically, asking a new question on StackOverflow is my last resort when nothing else that I've tried solved my problem. Any help is appreciated.

like image 883
Greg Whatley Avatar asked Mar 10 '16 03:03

Greg Whatley


1 Answers

Change your App.cs like this

  public App()
    {
        InitializeComponent();

        MainPage = new NavigationPage(new MainPage());//Very important add this..
        //MainPage = new MainPage(); //not like this        
    }
like image 53
Ranjithkumar Avatar answered Sep 24 '22 05:09

Ranjithkumar