Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate one Content page to another Content page from client project (IOS/Android) in xamarin forms?

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());
like image 355
Pavan V Parekh Avatar asked Apr 17 '15 14:04

Pavan V Parekh


People also ask

What is flyout page in Xamarin forms?

A flyout page typically displays a list of items, as shown in the following screenshots: The location of the list of items is identical on each platform, and selecting one of the items will navigate to the corresponding detail page.


1 Answers

"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 docs.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.

like image 153
ClintL Avatar answered Sep 21 '22 01:09

ClintL