简体   繁体   English

如何在模块中使用棱镜浏览多个视图

[英]How to navigate using prism for multiple views in Module

I'm new to Prism so need some help on navigation between views In my project I have just 4 views, so I have created all view in one module. 我是Prism的新手,因此需要一些视图之间导航的帮助。在我的项目中,我只有4个视图,因此我在一个模块中创建了所有视图。 I have created shell and bootstrapper. 我已经创建了shell和bootstrapper。 What I need to do is, I need to pass some data from one view to another(for eg, First view has list of employees, I select one employee and I will click Button to get the details of that employee). 我需要做的是,我需要将一些数据从一个视图传递到另一个视图(例如,第一个视图具有雇员列表,我选择一个雇员,然后单击“按钮”以获取该雇员的详细信息)。 Currently I'm using ViewModel first approach` 目前,我正在使用ViewModel第一种方法`

_container.RegisterType<DashboardView>();
_container.RegisterType<PrepareRunView>();

_container.RegisterType<IDashboardViewViewModel, DashboardViewViewModel>();
_container.RegisterType<IPrepareRunViewViewModel, PrepareRunViewViewModel>();
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(DashboardView));
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(PrepareRunView));
  1. In this case how do I do navigation between the views and pass data? 在这种情况下,如何在视图之间进行导航并传递数据?
  2. What do I need to specify in Module class Initialize function? 我需要在Module类的Initialize函数中指定什么?

Moreover in module class when I register both the views for same region, I'm able to see both the views, so I need to activate and deactivate my views also. 此外,在模块类中,当我为同一区域注册两个视图时,我能够看到两个视图,因此我还需要激活和停用我的视图。

Thanks in advance 提前致谢

The view-model of the first view (the one where you select an employee) needs a reference to Prism's IRegionManager object. 第一个视图的视图模型(选择雇员的视图模型)需要引用Prism的IRegionManager对象。 You navigate to the second view and pass it some data as follows, much like querystring values in a URL:- 您导航到第二个视图,并按以下方式将一些数据传递给它,就像URL中的querystring值一样:-

var uriQuery = new UriQuery();
uriQuery.Add("empid", "123");
// Add more name/value pairs if you wish!

var viewName = "your_view_name" + uriQuery;

_regionManager.RequestNavigate("your region name", viewName);

As you can see, you navigate to a view by specifying a view name. 如您所见,您可以通过指定视图名称导航到视图。 For this to work, you need to register your views under a name with your IoC container (how you do this depends on which container you use). 为此,您需要使用IoC容器在一个名称下注册视图(操作方式取决于您使用的容器)。

In the view-model of the view you are navigating to, implement the INavigationAware interface:- 在要导航到的视图的视图模型中,实现INavigationAware接口:

    public bool IsNavigationTarget(NavigationContext navigationContext)
    {
        return true;
    }

    public void OnNavigatedFrom(NavigationContext navigationContext)
    {
    }

    public void OnNavigatedTo(NavigationContext navigationContext)
    {
        // This will be called whenever the view is navigated to.
        // Extract the querystring value(s).
        var employeeId = navigationContext.Parameters["empid"];
        .. etc..
    }

You can use event aggregator for communication 您可以使用事件聚合器进行通信

http://msdn.microsoft.com/en-us/library/ff921122.aspx http://msdn.microsoft.com/en-us/library/ff921122.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM