shell - dynamic template layout

Topics: Prism v2 - Silverlight 2
May 4, 2009 at 10:04 PM
I am trying out Prism by taking an existing SL2 app and "prismisng" it. It is a pleasurable experience so far but I am not sure how to do some things so I'm looking for some advice please. I have 4 questions around what I think is the same subject. I may not be asking the correct questions so feel free to let me know if I am going in the wrong direction :)

I have started out with a shell template layout that defines 4 regions.
Now I would like to change my app so that when a user in a given role logs on...
UserRoleA sees a shell template with 2 regions
UserRoleB sees 3
UserRoleC sees 4 regions

How to achieve this? Can I provide more than one Shell template layout or can I change "the one and only" shell? Where is this best accomplished?

I would also like to display different views in the regions depending on the UserRole. Where is that logic best implemented?

I would like the ability to change the shell template layout (maybe swap the existing one for another??) based on a user action. So the user may be looking at a shell with 2 regions and then click a button that will change their screen to a shell with 4 regions.

If I can swap regions and shell templates do I need to create these from scratch each time or can I keep them "in memory" and just swap them in and out?

I hope the questions are not confusing!!
May 6, 2009 at 12:03 AM

Hi David,


I will try to answer your questions by just focusing on each of the numbers, so you can get a clear picture:

1.       As the Shell and View technical concept article explains, there is no specific need to have a single Shell. The Composite Application Guidance looks to ease the process of creating Composite Applications for WPF & Silverlight, so depending on your needs you can “take what you want from it”.

2.       There is not a particular way for performing user authentication in Prism. I would recommend you to create a service for this task. Based on this authentication service you can update your UI in the way you find best suiting. Different modules can consume this service to add regions and views accordingly.

3.       You can create / remove regions and views dynamically to get a similar behavior. Regions are added as attached properties of UI controls (such as TabControls, ContentControls, etc), so whether they are moved or not will not modify their behavior. The following threads explain how to dynamically create regions and how to dynamically remove regions.

4.       I do not know you particular scenario, but modules, services and views placed in regions (even if they are not shown) and will remain in memory. Therefore there is no need to create them each time you need to use them. Services, usually singletons, will most likely be placed in the container of your application (for example Unity) so they will remain "in memory" for the lifetime of the application.


You can get more information about regions and views from these articles from the Prism-v2 documentation:

·         UI Composition

·         Container and Services

·         How to: Add a Region


Please let me know if this helps.


Damian Schenkelman