一、首先看看文件的组织架构

module1 module2生成dll某块。Shell来显示管理模块

二,看看关键bootstrapper类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace wpfPrismTest
{
    using System.ComponentModel.Composition;
    using Microsoft.Practices.Prism.MefExtensions;
    using System.Windows;
    using Microsoft.Practices.Prism.Modularity;
    using System.ComponentModel.Composition.Hosting;
    using System.IO;  
    class QuickStartBootstrapper:MefBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            return this.Container.GetExportedValue<Shell>();
        }

protected override void InitializeShell()
        {
            base.InitializeShell();

Application.Current.MainWindow = (Shell)this.Shell;
            Application.Current.MainWindow.Show();
        }
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();
            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(this.GetType().Assembly));

if (Directory.Exists("./Modules"))
            {
                this.AggregateCatalog.Catalogs.Add(new DirectoryCatalog("./Modules"));
            }
        }
        //protected override void ConfigureAggregateCatalog()
        //{
        //    base.ConfigureAggregateCatalog();

//    // Add this assembly to export ModuleTracker
        //    this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(QuickStartBootstrapper).Assembly));

//    // Module B and Module D are copied to a directory as part of a post-build step.
        //    // These modules are not referenced in the project and are discovered by inspecting a directory.
        //    // Both projects have a post-build step to copy themselves into that directory.
        //    DirectoryCatalog catalog = new DirectoryCatalog("Modules");
        //    this.AggregateCatalog.Catalogs.Add(catalog);
        //}
        protected override IModuleCatalog CreateModuleCatalog()
        {
            // When using MEF, the existing Prism ModuleCatalog is still the place to configure modules via configuration files.

return new ConfigurationModuleCatalog();
            //return new DirectoryModuleCatalog() { ModulePath = @".\Modules" };

}
    }
}
还有module1 module类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.Prism;

using Microsoft.Practices.Prism.MefExtensions;
using Microsoft.Practices.Prism.Modularity;
using System.ComponentModel.Composition;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.MefExtensions.Modularity;

namespace Module1
{
    [ModuleExport(typeof(Module1), InitializationMode = InitializationMode.OnDemand)]
    public class Module1:IModule
    {
        [Import]
        public IRegionManager TheRegionManager { private get; set; }
        /// <summary>
        /// Notifies the module that it has be initialized.
        /// </summary>
        public void Initialize()
        {
            TheRegionManager.RegisterViewWithRegion("MarketRegion1", typeof(ModuleView1));
        }
    }
}
三、在shell后端代码添加如下代码

private void NavBarItem_Click(object sender, EventArgs e)
        {

moduleManager.LoadModule("Module1");
            ItemsControl ic = new ItemsControl();
            RegionManager.SetRegionName(ic, "MarketRegion1");
            documentPanel.Content = ic;

}

private void NavBarItem_Click_1(object sender, EventArgs e)
        {
            ItemsControl ic = new ItemsControl();
            RegionManager.SetRegionName(ic, "MarketRegion2");
            documentPanel.Content = ic;
        }

四、运行界面如下

wpf prism加载独立模块实例的更多相关文章

  1. 【.net深呼吸】WPF异步加载大批量图像

    如何在WPF中加载大批量数据,并且不会阻塞UI线程,尤其是加载大量图片时,这活儿一直是很多朋友都相当关注的.世上没有最完美的解决之道,咱们但求相对较优的方案. 经过一些试验和对比,老周找到了一种算是不 ...

  2. NGINX 加载动态模块(NGINX 1.9.11开始增加加载动态模块支持)

    NGINX 1.9.11开始增加加载动态模块支持,从此不再需要替换nginx文件即可增加第三方扩展.目前官方只有几个模块支持动态加载,第三方模块需要升级支持才可编译成模块. tinywan@tinyw ...

  3. 模拟jQuery中的ready方法及实现按需加载css,js实例代码

    这篇文章介绍了模拟jQuery中的ready方法及实现按需加载css,js实例代码,有需要的朋友可以参考一下     一.ready函数的实现经常用jQuery类库或其他类库中的ready方法,有时候 ...

  4. archlinux 加载loop模块,且设定loop设备个数

    如果loop模块没有编译进内核就要先加载loop模块 modprobe loop 然后更改/etc/modprobe.d/modprobe.conf(有些文章写是在/etc/modprobe.conf ...

  5. Angular.JS + Require.JS + angular-async-loader 来实现异步加载 angular 模块

    传统的 angular 应用不支持异步加载模块,必须在 module 启动的时候,所有模块必须预加载进来. 通过使用 angular-async-loader 库,我们可以使用 requirejs 等 ...

  6. Linux内核源码树建立加载hello模块

    在加载模块之前,书中说要先建立内核源码树,那么,如何建立内核源码树呢? 首先,要先知道你的OS的内核版本,用uname -r可以查得到 在/url/src/目录下可以看到对应的版本目录 如果没有可以用 ...

  7. [tp3.2.1]让默认页面: 加载Home模块的Index控制器;而让admin.php默认去加载Admin模块的Adminc控制器.

    QQ:让index.php默认加载Home模块的Index控制器;而让admin.php默认去加载Admin模块的Adminc控制器.AA:复制index.php命名为admin.php复制(新建)A ...

  8. 列出当前ARM开发板系统加载的模块

    lsmod 列出当前系统中加载的模块,其中左边第一列是模块名,第二列是该模块大小,第三列则是使用该模块的对象数目

  9. PHP无法加载MySQL模块

                在 将PHP根目录下libmysql.dll复制到c:\Windows\system32中 在Apache目录中的conf\httpd.conf 中加载libmysql.dll ...

随机推荐

  1. Yarn 内存分配管理机制及相关参数配置

    上一篇hive on tez 任务报错中提到了containter内存不足,现对yarn 内存分配管理进行介绍 一.相关配置情况 关于Yarn内存分配与管理,主要涉及到了ResourceManage. ...

  2. [CSP-S模拟测试]:蛇(DP+构造+哈希)

    题目传送门(内部题140) 输入格式 前两行有两个长度相同的字符串,描述林先森花园上的字母. 第三行一个字符串$S$. 输出格式 输出一行一个整数,表示有多少种可能的蛇,对$10^9+7$取模. 样例 ...

  3. nginx+uWSGI+django+virtualenv+supervisor发布web服务器流程

    导论 WSGI是Web服务器网关接口.它是一个规范,描述了Web服务器如何与Web应用程序通信,以及Web应用程序如何链接在一起以处理一个请求,(接收请求,处理请求,响应请求)基于wsgi运行的框架有 ...

  4. java 手机号/身份证(*)加密隐藏中间某几位几位

    //手机号 保留前3 后4 String phone = "18771632488"; System.out.println(phone.replaceAll("(\\d ...

  5. js关闭当前页面(窗口)的几种方式

    1. 不带任何提示关闭窗口的js代码  代码如下: <a href="javascript:window.opener=null;window.open('','_self');win ...

  6. jquery 使用on方法给元素绑定事件

    on方法在1.7版本中开始出现的,现在已经优先考虑on,并不是bind方法了. on( events [,selector] [,data] ,handler) event:为事件类型,可以有多个事件 ...

  7. Uep弹窗showModalDialog的使用

    function imageMaintain() { $.showModalDialog($$pageContextPath + "uepI/imageMaintain.do?service ...

  8. 服务器被攻击后当作矿机,高WIO

    __ 矿机特点:    操作系统反应慢. wio 非常高,一般轻松达到50%,甚至达到100%. 在/root/ 下存在 .ddg 隐藏路径.路径中有nnnn.db 二进制文件. /tmp ./usr ...

  9. robotFramework——FOR循环语句

    robotframework支持FOR循环语句,语法和Python的语法基本相同,但robotframework中,“FOR”关键字前面需要增加一个“:”,写成“:FOR”,其它与Python的语法相 ...

  10. Python学习笔记:(十三)错误和异常

    一.语法错误 在Python中语法错误称之为解析错误. 在语法分析器指出了出错的哪一行,并且在最先找到错误的位置标记了一个小小的箭头. 二.异常 1.异常处理 try except else fina ...