每次在PRISM中进行导航时如何创建新视图? [英] How to create a new view every time navigation occurs in PRISM?

查看:60
本文介绍了每次在PRISM中进行导航时如何创建新视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为新项目使用WPF4和PRISM4.

I'm using WPF4 and PRISM4 for my new project.

只有一个模块,其中包含多个视图. DI是统一完成的.当我第一次从ViewA导航到ViewB时,将创建ViewB并调用其构造函数.但是,当我尝试第二次,第三次导航到ViewB时,不会创建ViewB,但是会重用现有实例.

There is a single module with several views in it. The DI is done with unity. When I navigate from ViewA to ViewB for the first time, the ViewB is created and its constructor is called. But when I try to navigate to ViewB for the second, third time, the ViewB is not created, but existing instance is reused.

出于导航目的,我正在使用 IRegionManager.RequestNavigate .

I'm using IRegionManager.RequestNavigate for my navigation purposes.

我试图将 TransientLifeTimeManager 传递给 RegisterType Unity方法,但无济于事.

I've tried to pass TransientLifeTimeManager to RegisterType Unity methods, but to no avail.

是否有一种方法可以配置棱镜和/或统一以在每次导航到它时创建一个新视图?

Is there a way to configure prism and/or unity to create a new view every time I navigate to it?

谢谢.

推荐答案

方法是在您的view或viewModel上实现IRegionMemberLifetime,并在布尔属性KeepAlive中返回false,如下所示:

The way to do it is to implement IRegionMemberLifetime on your either your view or viewModel, and return false in the boolean property KeepAlive as follows:

public class EmployeeDetailsViewModel : IRegionMemberLifetime
{
    public bool KeepAlive
    {
        get { return false; }
    }
}

这篇关于每次在PRISM中进行导航时如何创建新视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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