RegisterViewWithRegion creates object

Topics: Prism v4 - Silverlight 4
Jan 5, 2011 at 1:46 PM

I'm new to Prism and the regions, so maybe I'm not understanding the use of regions properly.

I created a region in my shell that I want to load content in and out of.

When I call RegisterViewWithRegion, the view object is created and placed into the region automatically.  I do not want this behavior.  I would like the view object to be created when I navigate to the view with "RequestNavigate".  Otherwise, I could have a bunch of views created in memory that are never used.

Am I mis-understanding the use of regions in this case?

Thanks for your help.

Jan 5, 2011 at 2:47 PM


In order to achieve your scenario, you should only call RequestNavigate, and not RegisterViewWithRegion.

The RegisterViewWithRegion method is useful to fulfill the View Discovery approach, which means that a view will be automatically created inside a region when the control that hosts that region is added to the visual tree. You can read more about this in the UI Composition chapter from the Prism MSDN documentation.

Alternatively, Navigation provides a means to "coordinate changes to the UI as a result of the user's interaction with the application or internal application state changes". If you don't register the view with that region, and don't have that view created, the RequestNavigate method will internally resolve that view through the dependency injection container that you're using, and then add it to that region, without the need to have it constructed beforehand.

I hope you find this helpful.

Guido Leandro Maliandi


Jan 5, 2011 at 3:12 PM

This was helpful.  Thank you for the reply.