Same view instance - multiple regions

Topics: Prism v2 - Silverlight 2
Jun 15, 2009 at 9:51 AM

Hi there,

I'm stuck with a problem I haven't found a solution yet. Maybe someone has an idea:

I have a highly modular Silverlight Prism app, containing modules like "email" or "addresses", e.g. Each of these modules has it's own region, again containing nested child regions. But there is one area I would like to show in every module: a widget area. It should be exactly the same view instance (maintaining state when switching between modules).

The problem I'm faced with is, that I _need_ to have separate, named regions for the widget area inside of each module region. I cannot name those widget regions the same, because I'd get an error if I had multiple regions with the same name. Still, I want to show the exact same content/instance of my widgets in each module region ("address_widgetregion" and "email_widgetregion" should have the same content). Since Views are registered inside their containing regions, I cannot easily have a master region and re-use (cut & paste) the widget view in the currently active module region, because the view can only be registered within one region.

Do you have any ideas?

Best regards,

Jun 15, 2009 at 4:56 PM

Hi Tobi,

it sounds to me that you need to think about the problem from a slightly different viewpoint.

Why not have a single instance of the data which the 'widget' areas then display to the user.

So you can then have multiple instances of the view but they all display the same data - basic Observer pattern approach.



Jun 16, 2009 at 8:28 AM

Hi Niall,

thank you very much for your answer! Having a single instance of the data sounds reasonable, you're right.

What I can't (yet) imagine, is how "view states" will be part of that, too. I'm thinking e.g. of an accordion that's collapsed/open in one (instance of a) view - this should remain collapsed/open in the other widget views, too. So actually, the whole view should be reflected in the other instances.
What I also don't know right now is, how to do that in Prism: when populating a region, I'm constrained to using "this.container.Resolve<WidgetModuleView>()" or "regionManager.RegisterViewWithRegion("AddressModule_WidgetRegion", typeof(WidgetModuleView));" - which both 'just' instantiate my views. I can't step in and, e.g. stop instantiation to implement a singleton or something similar (can I??).

Do you have a (code) sample regarding doing this in Silverlight / Prism?

Best regards,


Jun 16, 2009 at 10:59 PM

Hi Toby,

sorry, I forgot / skipped the bit about maintaining the view state!

My first reaction would be to simply store this extra state information in a similar manner to the data that is being displayed, ie. in a central location. I'd look into the Model-View-ViewModel pattern if you're not currently using it as I believe the ViewModel may relate to the state information that you want to preserve. If so, you could share a single ViewModel between multiple instances of the view.

I don't have any such code but now that you mention it, I'm sure you can control the instantiation of objects within Prism as it simply uses a Dependency Injection framework behind the scenes. I have to admit that I'm not currently developing with Prism so my depth of specific knowledge is going to be slightly lacking! I'm hoping to get back to some smart client development soon though.

Sounds like the path of least resistance would be option one though!