简体   繁体   English

如何以 xamarin 形式从客户端项目(IOS/Android)将一个内容页面导航到另一个内容页面?

[英]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?如何以 xamarin 形式从客户端项目将一个内容页面导航到另一个内容页面?

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.我尝试在 GCMService 的 OnMessage 方法中使用以下代码。 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());

"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:选项1:

Swap out MainPage with your new page and use content pages.用您的新页面替换 MainPage 并使用内容页面。

App.Current.MainPage = your new content page

Option 2: (Probably the better option)选项2:(可能是更好的选择)

Make App.Current.MainPage a NavigationPage rather than a ContentPage then push your first content page to it.使 App.Current.MainPage 成为 NavigationPage 而不是 ContentPage 然后将您的第一个内容页面推送到它。 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/文档: 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.请注意,由于此答案出现了更好的导航方式,例如 docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/... app shell 路由。

Other choices are Prism MVVM or your own view model locator prismlibrary.com/docs/viewmodel-locator.html.其他选择是 Prism MVVM 或您自己的视图模型定位器prislibrary.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.使用这种内置导航的缺点是它缺少视图模型来查看模型导航,并且依赖于页面到页面,这会导致不必要的视图耦合和简单笨拙的导航。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM