Silverlight code

In the Silverlight Demo there are four projects, and one Web Solution.

Demo Solution
  • HelloWorldModule and ModuleB are Silverlight Libraries projects.

  • ModuleA and PrismSample are Silverlight Projects.

  • PrismSample.Web is the Web Solution to run the Silverlight project.

PrismSample project

In this project you will find two required files: Bootstrapper and Shell. There is an optional file ModulesCatalog.xaml

PrismSample project files

Bootstrapper

The Bootstrapper file is used to create, set the visual Root and Initialize the Shell component.

Bootstrapper and the Shell

In addition, the bootstrapper loads the modules that are used in the application.

Bootstrapper and modules

First, it casts the moduleCatalog instance, then it registers the modules with the AddModule method.

Here, the HelloWoldModule and the ModuleB are registers with the initializationMode in WhenAvailable. Remember that these projects are Silverlight Library, so they are in the references section like this:

Library projects

Module A is a Silverlight project and is loaded in a separate way. We create a moduleInfo to set all the information related to itself. Also, it is in a different .xap file, also called ModuleA.xap and the initialization mode is set in OnDemand, that means it will register in the bootstrapper but loaded under demand.

ModulesCatalog.xaml

There is another way to load the modules. In the Demo is not used, but you can find an example of this file:

Load modules through an Xaml file

Shell

The shell is a component used to display the application's UI. It is remarkably similar to a Silverlight Page. Usually, you will find regions to load modules into:

Shell regions

Module A is set to be loaded OnDemand, in this case you can load this module, clicking the Button in the interface. If you see the Button_Click_1 method, you will see the load of the ModuleA.

lazy loading of ModuleA

App.xaml.cs

The last step is to modify the Application_Startup method to load the bootstrapper.

creating the bootstrapper instance

Here, the bootstrapper instance is created, and the run method is called. With this change, the application will use PRISM instead of the default mechanism.

Modules

The modules are very similar to each other. HelloWorldModule, ModuleA, ModuleB contains a main class that is used to initialize the module.

Initialization class for ModuleA

Remember that this class needs to extend the IModule interface. Also, in the Initialize method the code registers the ModuleAView to be used in the ThirdRegion, so when you load this module, you will see the ModuleAView in the ThirdRegion. In case that you need to register a service, other views, or module, you can do it in this Initialize method.

Last updated

Was this helpful?