6

How to navigate one content page to another content page from client project in xamarin forms?

I have done implementing push notification in each platform in different way. I need to navigate to another content from current content page.

i try to use below code in GCMService's OnMessage method. My Problem is Second navigation content page's constructor are called and debug successfully. but my screen still display current page not to display second navigation content page.

App.Current.MainPage.Navigation.PushAsync (new SecondNavigationContentPage());

1 Answer 1

14

"Main Page" has to be a navigation page in order to navigate with the push pop navigation. You have a couple of options.

Option 1:

Swap out MainPage with your new page and use content pages.

App.Current.MainPage = your new content page

Option 2: (Probably the better option)

Make App.Current.MainPage a NavigationPage rather than a ContentPage then push your first content page to it. When you need to go to the second content page use the push navigation architecture.

App.Current.MainPage = new NavigationPage;
App.Current.MainPage.Navigation.PushAsync(Page1);
App.Current.MainPage.Navigation.PushAsync(Page2);

Docs: http://developer.xamarin.com/guides/cross-platform/xamarin-forms/controls/pages/

UPDATE

Note that since this answer much better ways have come along for navigation such as learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/… app shell routing.

Other choices are Prism MVVM or your own view model locator prismlibrary.com/docs/viewmodel-locator.html. The short coming in using this built in navigation is it lacks view model to view model navigation and depends on page to page which causes unwanted coupling of views and just plain clunky navigation.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.