Loading views from different modules on demand

Topics: Prism v4 - Silverlight 4
Apr 20, 2011 at 11:00 AM

I have interesting situation and am not sure what the best solution is. My problem is loading views from different modules into the region on demand.

The scenario is: user clicks on the button in the Shell UI and then I would like to load views from the multiple modules into one region.

Then, user clicks on one of the views/buttons and I need to load again multiple views from different modules into the region (or 2 regions) and remove/hide previously displayed views.

 What would be the best approach here?

Thanks for the help.

Apr 20, 2011 at 6:27 PM


Based on my understanding of your scenario, the most suitable approach to fulfill this would be to use Navigation. View based navigation concepts could help you to complete this scenario. You can read more in Chapter 8: Navigation from Prism MSDN documentation and you can check the View-Switching Navigation QuickStart where these concepts are covered.

Also you might find handy the Navigation Hand-On Labs exercises provided with Prism Training Kit.

I hope you find this information useful.


Miguel Bronzovic


Apr 22, 2011 at 12:51 AM

Hi Miguel,
Thank you for the quick response. I read and went through all the on-line documentation and examples. I couldn’t find the technique that covers my case or just I missed it. Here is what I need:
1. I need to instantiate multiple Views of the same type. I also have to pass parameters to the view.
2. Views belong to modules that are in separate projects.
3. I am using MEF
4. I need to display the views from Shell button events
5. I need to display views from the view button event. Views that I need to display may belong to the module that is in a different project.

Below is the technique that I am using and the problems I have. I am sure that there is better solution and/or technique but this is what I know at the moment.
1. In order to instantiate multiple view of the same type I need to use the following:
    this.regionManager.Regions["MainNavigationRegion"].Add(new NavigationItemView("Overall"), "OverallView");
    this.regionManager.Regions["MainNavigationRegion"].Add(new NavigationItemView("Projectors"), "ProjectorsView");
    Here I have to provide different names for the views (OverallView and  ProjectorsView).
    I also have to pass parameters to the view and I do that in the constructor.
2. The consequence of the approach above is that I have to have reference of the view type. The problem arises when I want to display view from the different project (module) since I don’t have reference of the view type.
3. One of the solution for the reference problem would be to use RequestNavigate. Unfortunately I cannot use it since the approach above requires view initialization like below and no [Export(“viewname”)].

    public partial class FillRateDashboard2 : UserControl, INavigationAware {
         public FillRateDashboard2() {
4. Same problem is with the item in Request 4.

Any ideas and suggestions here.

Apr 25, 2011 at 7:43 PM


Based on your description of your scenario, you could fulfill it by passing parameters during navigation. Prism provides the UriQuery class to help specify and retrieve navigation parameters.

You can read more here from Prism Navigation MSDN documentation.

Additionally, in case you need to obtain a reference to your exported classes without having a direct reference to the assembly that contains it, you just need to use the ServiceLocator to retrieve instances from the container. You can read more about ServiceLocator in Chapter 7: Composing the User Interface. Note that in that case, you need to have a reference to the interface of the class you’re going to retrieve. In the scenario that you’re explaining, however, this doesn’t seem to be necessary, since you can fulfill your requirement by using navigation with parameters as explained above.

Please let me know if this information helps you.


Miguel Bronzovic


Apr 25, 2011 at 8:29 PM

Hi Miguel,
That would certainly be acceptable solution, but I was unable to use RequestNavigate since I dont use [Export(“viewname”)] (see my post ubove).

Apr 25, 2011 at 9:28 PM

Hi Dragan,

The way to implement Region Navigation in Prism is to export the view using a contract name. If you need to pass a string to your view when it is navigated to, you could use the aforementioned approach of using a UriQuery in the navigation request. If you need to specify a dependency into your view when it is loaded, you could use Constructor Injection and specify that dependency in the constructor. Note that you don't necessarily have to use MEF; you could use any other dependency injection mechanism of your preference (for example Unity, which is also supported by Prism) to register and resolve the dependencies into your view.

I hope you find this helpful.

Guido Leandro Maliandi