Search code examples
c#wpfmoduleprismregion

PRISM: Nested regions in a region


The project is based on PRISM.

I've got a main region in the TabControl in the Shell.

        <!-- Main Region : A tab control -->
        <TabControl prism:RegionManager.RegionName="MainRegion" >
        </TabControl>

Then, I've got several Modules where all of them contains the same views. And must be added to the tab control region.

|_ModuleA
| |_ViewA
|
|_ModuleB
  |_ViewB

Check please the image. In tab ModuleA, it shows in the left of the tab content ViewA, and the right is a generic view because all the tabs must show the same UI.

enter image description here

How can I do this?


Solution

  • I guess 'lecrank' already answered the question. There's no problem to add Region inside other Region or View. What I did in my project:

    • Every Module receive a copy of IRegionManager and IEventAggregator objects in constructor (I use MEF)
    • In Initialize() function every Module register it own Regions with it own View, etc, etc...
    • Whenever event or program flow should be passed to another Module (for example) then I just .Publish() predefined event (CompositePresentationEvent) with parameters.
    • The Shell itslef it's just empty template that defined just couple 'global' Regions (like TabControl in your scenario) and everything that displayed on it is coming from different Modules Views and not implemented in Shell class or even in Shell containing project.

    So feel free to define and implement Regions and Views in another modules - just pass somehow the IRegionManager and IEventAggregator instances into Module class.