在棱镜中注册区域与添加区域之间有什么区别? [英] What is the difference between register a region to adding a region in prism?

查看:204
本文介绍了在棱镜中注册区域与添加区域之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个具有动态视图的区域(一个区域中有多个视图).区域内容需要通过ComboBox选择事件进行更改(comobox项是视图实例).我希望对ComboBox进行更改将通过所选视图项来更改该区域中的视图.

I want to create a region with dynamic views(multiple views in one region). The region content need to be changed by ComboBox selection event(the comobox items are view instances). I want that a change in the ComboBox will change the view in the region by the selected view item.

我的问题是什么:

MyView view= new MyView();
IRegion region = new Region();  
region.Name="MyRegion";  
regionManager.Regions.Add(region);
region.Add(view);
region.Activate(view);

收件人:

regionManager.RegisterViewWithRegion("MyRegion",type(MyView));

?

使用动态区域的最佳方法是什么?

What is the best way to use dynamic regions?

推荐答案

直接添加控件实例称为视图注入. 注册视图类型称为视图发现.

Adding a control instance directly is called view injection. Registering a view type is known as view discovery.

为什么要发现? Prism使用当前的ServiceLocatorContainer抓取一个实例(MEF,Unity,无论您选择什么).然后,它会自动添加视图.

Why discovery? Prism uses the current ServiceLocator the grab an instance from the Container (MEF, Unity, whatever you choose). It then adds the view automagically.

发现是更轻松的,因为所有视图都是延迟创建的(需要时).注入使您可以进行一些高级合成(如范围内的区域),但是您必须更加动手.

Discovery is leaner as all your views are created lazily (when they are needed). Injection lets you do some advanced compositions (like scoped regions) but you have to be more hands-on.

没有正确的答案,但是对于学习棱镜,我将使用视图发现(RegisterViewWithRegion).为了获得最佳结果,请使用常量来保存您的区域名称!

There is no right answer but for learning prism i would go with view discovery (RegisterViewWithRegion). For best results, use constants to hold your region names!

这篇关于在棱镜中注册区域与添加区域之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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