0

我很难理解 PRISM 如何INavigationService映射到Navigation.PushAsyncXamarin Forms 提供的标准。

我有一个开始使用 XF 的应用程序。它由一个MasterDetailPage主页组成,“详细信息”ContentPage包含许多按钮,这些按钮用于导航到其他功能。在 App.xaml.cs 中,我将 Application.MainPage 设置为包含在 NavigationPage“”中的主页实例MainPage = new NavigationPage(new HomePage())。然后,当我想显示功能页面时,我调用“ Navigation.PushAsync(new NewPage())”,这将显示新页面以及包含后退按钮的工具栏;然后,我可以使用设备上的后退按钮或工具栏中的后退按钮导航回我的主页。请注意,该应用程序在 Android 上运行。

然后我研究了集成 PRISM.Forms;我想使用它,因为我多年来一直将 PRISM 用于 WPF,并且认为它应该证明是有益的。我正在使用最新版本(6.3)。

我基于“PRISM 模板”创建了一个新应用程序,然后将差异复制到我现有的项目中......

  • “App”类现在基于“PrismApplication”而不是“PrismApplication.RegisterTypes”中的“Application”
  • 我为我希望能够导航到的所有表单调用“Container.RegisterForNavigation” 在“PrismApplication.OnInitialized”的末尾
  • 我打电话给“INavigationService.NavigateAsync($"/{nameof(NavigationPage)}/{nameof(HomeMasterDetailPage)}");”
  • 在我之前调用“Navigation.PushAsync”的地方,我调用“INavigationService.NavigateAsync(nameof(NewPage))”在“MainActivity”中,我使用“IPlatformInitializer”调用“App”构造函数

到目前为止,一切都很好。我按预期看到了我的主页。但是,当我导航到“NewPage”时,工具栏中没有后退按钮(尽管我仍然有来自 的“汉堡包”菜单MasterDetailPage),如果我使用设备上的后退按钮,它会将我返回到操作系统。该页面似乎已作为 MasterDetailPage 的“内容”部分插入,而不是作为新的子页面导航到它。

我确信这不是设计使然,因此我误解了一些东西,但有人可以指出我正确的方向,否则我觉得我将不得不放弃 PRISM 并寻找替代方案。

在尝试将登录屏幕引入组合时,我也遇到了问题。我首先调用“ INavigationService.NavigateAsync($"/{nameof(NavigationPage)}/{nameof(LoginPage)}");”,然后如果登录成功,我调用“ INavigationService.NavigateAsync($"/{nameof(NavigationPage)}/{nameof(HomeMasterDetailPage)}");”进入主页;这里的问题是,在显示主页 (a MasterDetailPage) 时,我不再看到“汉堡包”按钮来打开页面的“主”部分。我怀疑这可能也与我使用INavigationService不正确有关,但如果不是,我可以将其作为一个单独的问题提出。

4

1 回答 1

0

Prism's INavigationService essentially maps to the Xamarin Forms INavigation in this way: INavigationService.NavigateAsync => INavigation.PushAsync (or PushModalAsync if you set the useModal flag to true), & INavigationService.GoBackAsync => INavigation.PopAsync.

The INavigationService uses the container to resolve any pages that you specify in the Uri that you pass it and then pushes them onto the Navigation Stack. You may want to check out the various samples available, including the "HamburgerMenu" project which shows the use of a MasterDetailPage and it uses a LoginPage.

于 2017-04-13T14:52:09.210 回答