Prism 请求导航到新视图 [英] Prism RequestNavigate to new view

查看:32
本文介绍了Prism 请求导航到新视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 WPF Prism 6autofac 一起使用,并且在视图之间导航时遇到问题.我有一个视图,我只想在离开它之前一直保持活动状态,下次导航到它时,我想创建此视图的新版本.

I am using WPF Prism 6 with autofac and having issues navigating between views. What I have is a view that I only want to keep alive till I leave it, and the next time I navigate to it, I want to create a new version of this view.

加载时,我注册了一个IModule,它具有以下代码

On load, I regist an IModule that has the following code

_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, 
                                      typeof(DxfDisplay.Views.DxfDisplay));

这会注册我的视图并且系统在初始加载时工作,我在视图模型上实现了 INavigationAwareIRegionMemberLifetime 接口并具有 public bool KeepAlive =>false; 实现 IRegionMemberLifetime 以便在我完成后处理我的视图.

This registers my view and the system works on initial load, I implement the INavigationAware and IRegionMemberLifetime interfaces on the view model and have public bool KeepAlive => false; implementing the IRegionMemberLifetime so that my view is disposed when I am done.

当我离开这个视图时一切正常,但是当我尝试使用

When I navigate away from this view everything is fine, but when I attempt to navigate to navigate to the view using

_regionManager.RequestNavigate(RegionNames.MainRegion, 
                               new Uri("DxfDisplay", UriKind.Relative), parameters);

未打开视图,也未调用视图模型构造函数.为了使导航正常工作,我需要再次向该区域注册视图.或者,如果我将 KeepAlive 更改为 true,我可以导航回原始视图,但如果 INavigationAware.IsNavigationTarget 返回 false,则我无法生成新视图.

The view is not opened and a view model constructor is not called. To make the navigation work correctly, I need to register with view with the region again. Or if I change the KeepAlive to true I can navigate back to the original view, but I cannot generate a new view if INavigationAware.IsNavigationTarget returns false.

我的问题是如何向区域管理器注册视图,以便在调用 _regionManager.RequestNavigate 时,它将创建视图的新实例并显示它.我觉得我错过了一些简单的东西,只是忽略了它.

My question is how do I register the view with the region manager in such a way that when I call _regionManager.RequestNavigate, it will create a new instance of the view and display it. I feel like I am missing something simple and just overlooking it.

推荐答案

_builder.RegisterTypeForNavigation();

这篇关于Prism 请求导航到新视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆