How to populate catalog from xaml file

Topics: Prism v4 - Silverlight 4
Aug 12, 2010 at 6:39 AM

Hi

I would like to populate my catalog from a xaml file. Unfortunatly nothing is display in the shell.

When i populate in code, everything work fine.

I add a silverlight control file and i delete the code-behind.

I copy the ModuleA.xap in the ClientBin directory.

ModuleCatalog.xaml

<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="ModuleA.xap" 
      ModuleName="ModuleA" 
      ModuleType="ModuleA.ModuleA, ModuleA, Version=1.0.0.0"
      InitializationMode="WhenAvailable"/>
</Modularity:ModuleCatalog>
MEFBootstrapper :
  protected override IModuleCatalog CreateModuleCatalog()
        {
            return Modularity.ModuleCatalog.CreateFromXaml(new Uri("/HDMSApplication;component/ModuleCatalog.xaml", UriKind.Relative));
        }
Thanks
Aug 13, 2010 at 7:51 PM

Hi,

I do not know your exact scenario, but it seems that the problem for initializing your ModuleA resides in the ModuleType specified. You may need to specify a more fully-qualified type name. That said, your ModuleType could look like the following:

<Modularity:ModuleInfo Ref="ModuleA.xap" ModuleName="ModuleA"
ModuleType="ModuleA.ModuleA, ModuleA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
InitializationMode="WhenAvailable" />

Additionally it is necessary to decorate your module class initializer as is shown below:

[ModuleExport(typeof(ModuleA))] public class ModuleA : IModule

For more information on this topic you could take a look at the MEF Modularity Quickstart (download it here). Please note that this Quickstart contains a log, which shows in run-time the state when loading its modules. Therefore, it might be useful for playing with module loading.

Please let me know if this helps.

Fernando Antivero
http://blogs.southworks.net/fantivero

 

 

Aug 13, 2010 at 8:26 PM

Also, make sure that the references to the Prism libraries in your module projects have the "Copy Local" flag set to false.  Otherwise, due to how MEF loads XAPs, the core Prism libraries get loaded twice, the imports are done twice, and you end up with MEF throwing a number of exceptions.