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

标签 c# xamarin xamarin.forms navigation

如何在 xamarin 表单中从一个内容页面导航到另一个内容页面?

我已经以不同的方式在每个平台上实现了推送通知。我需要从当前内容页面导航到另一个内容。

我尝试在 GCMService 的 OnMessage 方法中使用以下代码。 我的问题是第二个导航内容页面的构造函数被调用并成功调试。但我的屏幕仍然显示当前页面不显示第二个导航内容页面。

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

最佳答案

“主页”必须是导航页面才能使用推送弹出导航进行导航。您有几个选择。

选项 1:

用新页面替换 MainPage 并使用内容页面。

App.Current.MainPage = your new content page

选项 2:(可能是更好的选项)

将 App.Current.MainPage 设为 NavigationPage 而不是 ContentPage,然后将您的第一个内容页面推送到它。当您需要转到第二个内容页面时,请使用推送导航架构。

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

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

更新

请注意,由于这个答案已经出现了更好的导航方式,例如 learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/... app shell 路由。

其他选择包括 Prism MVVM 或您自己的 View 模型定位器 prismlibrary.com/docs/viewmodel-locator.html。使用这种内置导航的缺点是它缺少 View 模型来查看模型导航,并且依赖于页面到页面,这会导致不必要的 View 耦合和简单笨拙的导航。

关于c# - 如何以 xamarin 形式将一个内容页面从客户端项目(IOS/Android)导航到另一个内容页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29701621/

相关文章:

c# - mono 的逆变编译异常

json - 使用 xamarin 从 URl 中检索 JSON 消息并显示在 TableView 中

android - 重新安装应用程序时旧数据出现在 SQLite 数据库中

c# - Xamarin.Forms - ContextMenu 上的绑定(bind)

c# - 如何更改 Team City 中 NUnit 测试的工作目录?

javascript - WebView2:通过 Javascript 代码在 C# 中设置对象属性

.net - 尝试使用 PCL 项目中的 PCLStorage 读取文件时出现异常

xamarin.forms - iOS 上的 Xamarin Forms UIWebView 弃用

c# - 在没有 .NET Core SDK 的情况下将 ASP.NET Core MVC 作为控制台应用程序项目运行

c# - 编译 Xamarin 应用程序。加载程序集时出现异常。找不到文件异常