scoped regions: PrismTrainingKit 4.0 / UI Composition Hands-On Lab

Topics: Prism v4 - WPF 4
Feb 18, 2013 at 8:45 PM
Hi Prism Experts,
First i want to thank you because you are the only guidance for us for lack of books on prism.
I have an application similar to PrismTrainingKit 4.0 /UI Composition Hands-On Lab / Exercise 3
(where i need to use scoped regions) with some deviation so i need your help to implement it with the following modifications to use it as a guide to complete my application:
1-using MEF as container and RequestNavigate & UriQuery for view navigation

2-If there is another tab in the MainRegion that will display SpareParts for example, and another user control will be displayed in the BottomRegion with diffrent tabs, now the user controls in the BottomRegion will interchange depending on i'm selecting from Product List or Spare Parts
list, how would you implement this?

Thanks in advance for your very valuable help
Feb 19, 2013 at 8:32 PM

Based on my understanding, in order to migrate the UI Composition HOL from Unity to MEF , first you will need to change how the classes are registered in the container. Basically speaking you will need to add the required attributes like Export and ImportingConstructor to the corresponding classes. If a class was previously registered through an interface in Unity (for example the UIMessagesService) you will also need to register it like this in MEF too : [Export(typeof(IUIMessagesService)]. After that you will need to refactor the WorkshopBootstrapper to inherit from the MefBootstrapper class and configure it accordingly. You can find more information about the differences between Unity and MEF in the following chapters of the Prism documentation:
Regarding changing the UI Composition method to navigation, it would be helpful to know which regions and views you want to manage through navigation, specially in an scenario similar to the aforementioned HOL where most views are being manually composed through presenters. Also, please take into account that currently Prism does not support the scenario of navigating to a view while attaching a scoped region manager to it. For example, if you navigate to a ProductDetailsView you wouldn't be able attach a region manager to in like in the OnProductSelected method of the ProductController class. Also, take into account that you will need to register the corresponding views to be used in navigation: [Export("ViewClassName")] . You can find more information about this in the following chapter of the Prism documentation:
Finally, there are several approaches you can use to achieve the behavior you are mentioning. Which one is most suitable will depend of your personal preferences and the requirements of your scenario. For example, if you want to change the contents of the BottomRegion upon selecting a product or a spare part, a possible approach could be to bind the SelectedItem property of the DataGrid to a property in the view model: SelectedItem="{Binding SelectedItem, Mode=TwoWay}" . Then in the setter of the view model's property, you could react when the selected item is changed and change the views in the BottomRegion . Another example of a different approach is what the UI Composition HOL does in the OnProductSelected method of the ProductController class.

I hope you find this useful,

Damian Cherubini