How do I create a ModulesCatalog.xaml file in VS

Topics: Prism v4 - Silverlight 4
Jun 15, 2012 at 12:40 AM

I'm trying to add a Modules Catalog as a file in VS and I don't know how.

I want to use

ModuleCatalog.CreateFromXaml(new Uri("ModulesCatalog.xaml", UriKind.Relative));

in my CreateModuleCatalog() method inside the Bootstrapper class.

I'm using Prism v4 in a Silverlight 4 project.

I don't know how to create this ModulesCatalog.xaml, I tried creating a UserControl and deleting its code behind, I also tried creating an xml file and changing it's extension to xaml.

No matter what I do, I keep getting these error messages when compiling:

"The tag "ModuleCatalog" does not exist in ..." and so on.

 What can I do to create this ModuleCatalog.xaml file in VS?

Developer
Jun 15, 2012 at 1:36 PM
Edited Jun 15, 2012 at 1:38 PM

Hi,

Have you tried, adding a new file to your main project named ModulesCatalog.xaml using the XML file template as you mentioned but making sure its Build Action is set to "Resource". I believe this could be related to your problem.

Also, regarding how to achieve remote module loading, I believe you could find the "Modularity Hands on Lab, Exercise 3" from the Prism Trainig Kit useful, which includes a step-by-step guidance on how to configure modules in code and using a XAML ModulesCatalog. Also, in this same Trainig Kit, but in the MEF Lab you could find another similar example but using MEF.

I hope you find this helpful,

Agustin Adami
http://blogs.southworks.net/aadami

Jun 15, 2012 at 1:38 PM

Thank you.

 

I'll try it.

Jun 15, 2012 at 2:58 PM
Edited Jun 15, 2012 at 3:11 PM

Hi Agustin,

I don't know how to follow along with the hands on lab, execise 3. I open the project and see it all done in VS, but I don't know how they do things, I guess this is not the way a Hands On Lab works, I did one once (on VS) but I don't remember how I used it.

I remember there were some guidance, and it was very pleasant to do...

 

Nevertheless, I tried to add it as a xml template, then changed its build action to resource, and then added the ModuleCatalog definitions (this is an exercise)

<Modularity:ModuleCatalog 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:Modularity="clr-namespace:Microsoft.Practices.Composite.Modularity;assembly=Microsoft.Practices.Composite">
    <Modularity:ModuleInfo 
        Ref="Patients.Client.Modules.Patients.xap" 
        ModuleName="PatientsModules" 
        ModuleType="Patients.Client.Modules.Patients.PatientsModule, Patients.Client.Modules.Patients, Version=1.0.0.0" />
    <Modularity:ModuleInfo 
        Ref="Patients.Client.Modules.MedicalStaff.xap" 
        ModuleName="MedicalStaffModules" 
        ModuleType="Patients.Client.Modules.MedicalStaff.MedicalStaffModule, 
            Patients.Client.Modules.MedicalStaff, Version=1.0.0.0" />
</Modularity:ModuleCatalog>

But the IDE keeps showing the designer window, and trying to interpret those lines mistakenly, throwing some errors, saying that the type Modularity:ModuleCatalog was not found... etc.

 

 

Developer
Jun 15, 2012 at 4:53 PM

Hi,

In the folder where you installed the Prism Training Kit mentioned by Agustin you will find a folder named "1-Modularity" which contains the Modularity Hands On Lab. Inside this folder is a Word document named "Modularity-HOL.docx" which contains the step-by-step description for each exercise. If you wish to follow an specific exercise in this lab (like the Exercise 3 mentioned by Agustin) you will also find a folder containing a solution for each exercise. Inside those you should open the solution stored in the "Begin" folder and follow the instructions described in the "Modularity-HOL.docx" document for the corresponding exercise. As far as I know this is how most of Microsoft's hands on lab are structured.

Regarding the code snippet you posted of your module catalog, take into account that the Microsoft.Practices.Composite assembly is a Prism v2 assembly. If you are using Prism v4, you should replace this line of your module catalog:

xmlns:Modularity="clr-namespace:Microsoft.Practices.Composite.Modularity;assembly=Microsoft.Practices.Composite"

With the following one (which uses the Prism v4 assembly:)

xmlns:Modularity="clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism"

You can find more information about declaring module catalogs in a XAML file in the following section of Prism's documentation:

I hope you find this useful,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Jun 15, 2012 at 7:15 PM

 

Thank you Damian.