Xamarin.forms 服务中的Prism导航仅在无法导航回多个位置时才起作用
我有一个使用Prism模板包(2.0.7)创建的Prism Xamarin.Forms应用程序。 所有软件包都是最新的:Xamarin.forms 服务中的Prism导航仅在无法导航回多个位置时才起作用,xamarin.forms,prism,Xamarin.forms,Prism,我有一个使用Prism模板包(2.0.7)创建的Prism Xamarin.Forms应用程序。 所有软件包都是最新的: Xamarin.表格v2.5.0.91635 Android.*v26.1.0.1 Prism.DryIoc.Forms v7.0.0.168-pre(无法更新到v7.0.0.269-pre,因为Android渲染器在启动时出现NullReferenceException,但是我的主应用程序正在使用269-pre,没有这个问题) 我在上托管了示例应用程序 我有以下组成部分
- Xamarin.表格v2.5.0.91635
- Android.*v26.1.0.1
- Prism.DryIoc.Forms v7.0.0.168-pre(无法更新到v7.0.0.269-pre,因为Android渲染器在启动时出现NullReferenceException,但是我的主应用程序正在使用269-pre,没有这个问题)
- 模块“附件”(棱镜模块)
- 模块“查看器”(棱镜模块)
- 服务“AttachmentService”在接口为Singleton的容器中注册
public AttachmentService(INavigationService navigationService)
{
this.navigationService = navigationService;
}
public async void OpenAttachmentWithViewer(object attachment)
{
// ToDo: handle parameter proberbly
var attachmentType = "image";
// select correct viewer
if (attachmentType == "image")
{
// navigate to image viewer
var navParams = new NavigationParameters();
navParams.Add("object",attachment);
var navTask = this.navigationService.NavigateAsync(
"ImageViewerPage",
navParams,
useModalNavigation: false);
await navTask;
var result = navTask.Status;
Debug.WriteLine($"Navigation State is {result}");
}
}
我试图检查导航任务结果状态,它总是“RANTO完成”
修改AttachmentsPageViewModel以直接使用Prism NavigationService导航,而不是使用该服务,不会导致以下行为:
private void OnOpenAttachment()
{
// ToDo: get the selected attachment
object selectedAttachment = null;
// navigating inside a service -- not working when navigating back to MainPage
//this.attachmentService.OpenAttachmentWithViewer(selectedAttachment);
// navigation from view model -- working
var navParams = new NavigationParameters();
navParams.Add("object", selectedAttachment);
this.navigationService.NavigateAsync("ImageViewerPage", navParams, useModalNavigation: false);
}
提示:我将我的主应用程序从基于PCL切换到新的基于.NETStandard的解决方案,并且已经使用Prism v6.3.0.1成功实现了类似的功能。此功能在端口关闭后甚至没有导航过一次
其实我不知道怎么解决这个问题
是否可以查看Prism NavigationService以确定为何不进行导航?
我在Prism存储库中还没有发现任何已知的bug。您不能在其他服务中使用NavigationService,特别是如果该服务是单例的话。表单中的导航是特定于页面的,并且仅在关联页面的上下文中有效。相反,您的服务应该返回一个结果,并且您应该基于该结果从您的VM进行导航。不要试图在服务中导航。谢谢您的快速回答。我以前使用Prism 6的基于PCL的应用程序在服务中使用复合命令进行导航(包含在app.xam.cs中注册的导航调用的命令)。我想这也很糟糕吧?顺便说一句:我真的很喜欢棱镜