Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between register a region to adding a region in prism?

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.

My question what is the difference between :

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

To:

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

?

What is the best way to use dynamic regions?

like image 542
user436862 Avatar asked Feb 16 '14 17:02

user436862


People also ask

What is region in Prism?

Prism regions are essentially named placeholders within which views can be displayed. Any control in the application's UI can be a declared a region by simply adding a RegionName attached property to it, as shown here.

What is WPF region?

A region is a placeholder in the application UI into which modules are injected. You can mark a control as a region using any of the following approaches. Set the UIRegion. Region attached property. XAML.


2 Answers

If you want a different views to be displayed in the same region, you need to use RequestNavigate or view injection which you have used in your first method

RegisterViewWithRegion will associate the Region with the view, so that every time the control where the region is hosted become part of the visual tree the view is automatically resolved and displayed.

See the msdn entry for more information

like image 82
Jimmy Avatar answered Sep 21 '22 01:09

Jimmy


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

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.

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!

like image 38
Gusdor Avatar answered Sep 21 '22 01:09

Gusdor