<p>I am considering building a application using PRISM (Composite WPF Guidance/Library). The application modules will be vertically partitioned (i.e. Customers, Suppliers, Sales Orders, etc). This is still all relatively easy... I also have a Shell with a main region were all the work will happen but now I need the following behavior: I need a menu on my main Shell and when each one of the options gets clicked (like customers, suppliers, etc) I need to find the module and load it into the region (Only 1 view at a time)? </p>

<p>Does anybody know of any sample applications with this type of behavior? All the samples are more focused on having all the modules loaded on the main shell? And should my menu bar also be a module?</p>

<p>[<strong>UPDATE</strong>] How do I inject a module into a region based on it being selected from a menu? All the examples show that the module injects the view into the region on initialize? I need to only inject the view if the module is selected on a menu?</p>

[{'answer_id': 49304, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 0, 'selected': False, 'text': '<p>It\'s not clear what you mean saying "find the module and load it into the region". You can load module\'s view and add it to shell. Composite UI app block and CompositeWPF are built on top of the IoC pattern. It means that your modules should inject their menu items in shell\'s menu strip or subscribe to events generated by shell.</p>\n'}, {'answer_id': 169618, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>You could have your main region be a ContentControl, this way only 1 view will be active at a time.\nYou can also load your modules "On Demand". There is a Quickstart that shows you how to do this. You should also keep in mind that if the module was already initialized once, initializing it for a second time will not execute the Initialize() method on the module.\nIt might be useful that when you click on the menu, this will load the module on demand (which will not load the view yet) and then you can fire an event through EventAggregator, so the module can now add the view (use the named approach for not adding the view twrice) and the Activate the view (which will make sure the view is shwon in the region).</p>\n\n<p>Hope this helps,\nJulian</p>\n'}, {'answer_id': 183219, 'author': 'rudigrobler', 'author_id': 5147, 'author_profile': 'https://Stackoverflow.com/users/5147', 'pm_score': 2, 'selected': False, 'text': '<p>Just finished watching <a href="http://www.dnrtv.com/default.aspx?showNum=124" rel="nofollow noreferrer">Brian Noyes on Prism</a> at dnrTV. This answered all my question... </p>\n'}, {'answer_id': 881213, 'author': 'Scott Barnes', 'author_id': 94167, 'author_profile': 'https://Stackoverflow.com/users/94167', 'pm_score': 2, 'selected': False, 'text': '<p>Yes PRISM will help you out here.</p>\n\n<p>A number of things here worth mentioning.</p>\n\n<blockquote>\n  <p><strong>RE: Is Prism right for me?</strong></p>\n</blockquote>\n\n<p>You can load a Module on Demand. PRISM has the capabilities of loading a module at RunTime, so in your case if you bootup the said solution using Shell and ModuleA. Your user then triggers an event (ie Menu choice) it can then allow you to dynamically load ModuleB and then inject that into play. To be clear though, you really need to sit down and do your homework here as you need to ensure ModuleB doesn\'t have any of its own dependencies on other modules etc (typically its wise to use an Infrastructure Module. I\'ve used techniques where i have a manifest of modules that i lookup in XML that lists its absolute dependencies and then I make sure they are loaded first, then I load ModuleB).</p>\n\n<p><em>See <strong>Load Modules on Demand</strong> via PRISM help docs (Development Activities). Also lookup <strong>Prepare a Module for Remote Downloading</em></strong> </p>\n\n<blockquote>\n  <p><strong>RE: Injecting a view at runtime</strong></p>\n</blockquote>\n\n<p>To inject a View into a Region via Menu is a simple case of accessing the IRegionManager and then adding it. To do this, make sure in your Constructor for the said ViewModel/Presenter/Controller you\'re using put:</p>\n\n<pre><code>MyConstructor(IRegionManager regionManager, IUnityContainer container) \n</code></pre>\n\n<p>As with PRISM you can pretty much add any object you want into your construct and PRISM will ensure it arrives there on time and on budget (hehe).</p>\n\n<p>From there its the normal approach you\'d take with adding a view... eg:</p>\n\n<pre><code>IMyViewInstance myViewInstance = this.container.Resolve&lt;IMyViewInstance&gt;();\nIRegion myRegion = this.regionManager.Regions["YourRegion"];\nmyRegion.add(myViewInstance);\nmyRegion.Active(myViewInstance);\n</code></pre>\n\n<p>And all should come together! :)</p>\n\n<p>Note:</p>\n\n<ul>\n<li>Make sure you set a local reference to the container and regionManager at Construct (this.container = container etc).</li>\n<li>If you\'re not sure where the above namespaces exist, right click on IUnityContainer for example and let Visual Studio RESOLVE it (right click menu)</li>\n<li>Put the Add logic into your Menu Event that or use a central method - whichever blows your hair back :)</li>\n</ul>\n\n<p><strong>Scott Barnes - Rich Platforms Product Manager - Microsoft.</strong></p>\n'}, {'answer_id': 3321851, 'author': 'renlesterdg', 'author_id': 400607, 'author_profile': 'https://Stackoverflow.com/users/400607', 'pm_score': -1, 'selected': False, 'text': '<p>to save you time, check <a href="http://johnpapa.net/building-a-presentation-framework-with-prism-for-silverlight" rel="nofollow noreferrer">John Papa\'s Presentation Framework article</a>. It will be more easy if you have 3rd object(<code>Screen Conductor</code>) to handle your screens in showing or hiding from regions.</p>\n'}]
['https://Stackoverflow.com/questions/49299', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5147/']