Problem with PRISM + MEF

Topics: Prism v4 - Silverlight 4
Apr 7, 2011 at 6:29 PM

Hello I'm new to PRISM and MEF and I have been looking from other threads about how to do what I have done so far, with complete success I must say thanks to the help users provide here, but I'm stuck right now.

I will explain the situation.

I have a main xap (let's call it that way) that whenever a user clicks an option from a treeview it loads an external module from another xap (so far this is working).
In this other xap I load I have right now another region too in the shell view where I load a view from that same xap (this is working too), but if I click to add another instance of this xap using RequestNavigate, I get an exception about the region inside this xap already exists.

I have read about scoped regions, but looks like I don't know how to implement them.

In this loaded xap I have two modules declared, one that acts like the external module to let the main xap load it, and an 'inner' one that prepares the regions inside the xap.

As I understand (maybe I'm wrong) if I set the external module to create the scoped region of all the application, every region inside it would have to act independently from the main region right?

ListView view = new ListView();
IRegionManager rm = regionManager.Regions("MainRegion").Add(view, null, true);

I have those two lines in the Initialize method of the 'external' module, but looks like it's not working at all, as when I try to instantiate a second view it produces the exception saying that the inner region name already exists.
What I'm doing wrong?

Apr 8, 2011 at 10:38 AM
Edited Apr 8, 2011 at 10:56 AM

I have used now the approach by guidomaliandi from this thread:

So far it uses my custom RegionNavigationContentLoader class, and now I can instantiate two times the main view, but a third try will give me the exception

Apr 8, 2011 at 12:18 PM

Yay, got it working.

I modified the line where guidomaliandi said:

region.Add(view, null, true);

And that did the trick :)
URLS for people interested   - C# Version   - VB.NET Version

Apr 8, 2011 at 1:58 PM


I'm glad that you've solved your problem. Thank you for sharing your insight with the rest of the community, and for pointing that mistake out. I've modified my post to reflect the change you've mentioned.


Guido Leandro Maliandi