Adding Module to Project in WPF

Adding Module to Project

  1. Add a new class library project to your solution. To dothis, right-click the your project solution node in SolutionExplorer, point to Add, and then click New Project. In the Projecttypes list, select Windows in the Visual C# node. In the Templatesbox, click Class Library. Finally, set the project's name tosimpleprismapplicationModule, and then click OK. The followingillustration shows your solution. Solution with a module namedsimpleprismapplicationmodule
  2. Addreferences in your module to the following WPF assemblies. To dothis, right-click the simpleprismapplicationmoduleproject in Solution Explorer, and then click Add Reference. In theAdd Reference dialog box, click the .NET tab, click the followingassemblies, and then click OK:

    • PresentationCore.dll
    • PresentationFramework.dll
    • WindowsBase.dll
    • System.Xaml.dll
       
  3. Add references in your module to the Microsoft.Practices.Prism.dll Prism Library assemblies. To do this, right-click theHelloWorldModule project in Solution Explorer, and then click AddReference. In the Add Reference dialog box, click the Browse tab,click the following assemblies, and then click OK:
  4. Rename the Class1.cs file to simpleprismapplicationmodule.cs. Openthe file simpleprismapplicationmodule.cs and impliment theMicrosoft.Practices.Prism.Modularitynamespacein the class.
  5. Implement the IModuleinterface in simpleprismapplicationmodule class and create theconstructure of this class.
  6. Add a Views folder having name Viewto store the views of your application to thesimpleprismapplicationmodule project again add one more folder andrename to ViewModelto store the viewmodels.

    Note:- Above mentioned folders can be created in the simpleprismapplication project also, but it is good pratice to create a separate module to for manage code.
     
  7. In your shell project,add a reference to the simpleprismapplicationmoduleproject. Open theBootstrapper.cs file and explore the ConfigureModuleCatalog method.The method implementation is shown in the following code.

    protected override void ConfigureModuleCatalog()
    {
    base.ConfigureModuleCatalog();
    }
     
  8. Update theConfigureModuleCatalog method to register thesimpleprismapplicationmodule module with the module cataloginstance. To do this, you can add bellow codes in theConfigureModuleCatalog bellow the base.ConfigureModuleCatalog();code.

    ModuleCatalog moduleCatalog= (ModuleCatalog)this.ModuleCatalog;
    moduleCatalog.AddModule(typeof(simpleprismapplication.simpleprismapplicationmodule));
     
  9. Now addin module andregister module application with shell is done next steps is addingview to application
     
Ebook Download
View all
Learn
View all