wpf prism加载独立模块实例
一、首先看看文件的组织架构

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加载独立模块实例的更多相关文章
- 【.net深呼吸】WPF异步加载大批量图像
如何在WPF中加载大批量数据,并且不会阻塞UI线程,尤其是加载大量图片时,这活儿一直是很多朋友都相当关注的.世上没有最完美的解决之道,咱们但求相对较优的方案. 经过一些试验和对比,老周找到了一种算是不 ...
- NGINX 加载动态模块(NGINX 1.9.11开始增加加载动态模块支持)
NGINX 1.9.11开始增加加载动态模块支持,从此不再需要替换nginx文件即可增加第三方扩展.目前官方只有几个模块支持动态加载,第三方模块需要升级支持才可编译成模块. tinywan@tinyw ...
- 模拟jQuery中的ready方法及实现按需加载css,js实例代码
这篇文章介绍了模拟jQuery中的ready方法及实现按需加载css,js实例代码,有需要的朋友可以参考一下 一.ready函数的实现经常用jQuery类库或其他类库中的ready方法,有时候 ...
- archlinux 加载loop模块,且设定loop设备个数
如果loop模块没有编译进内核就要先加载loop模块 modprobe loop 然后更改/etc/modprobe.d/modprobe.conf(有些文章写是在/etc/modprobe.conf ...
- Angular.JS + Require.JS + angular-async-loader 来实现异步加载 angular 模块
传统的 angular 应用不支持异步加载模块,必须在 module 启动的时候,所有模块必须预加载进来. 通过使用 angular-async-loader 库,我们可以使用 requirejs 等 ...
- Linux内核源码树建立加载hello模块
在加载模块之前,书中说要先建立内核源码树,那么,如何建立内核源码树呢? 首先,要先知道你的OS的内核版本,用uname -r可以查得到 在/url/src/目录下可以看到对应的版本目录 如果没有可以用 ...
- [tp3.2.1]让默认页面: 加载Home模块的Index控制器;而让admin.php默认去加载Admin模块的Adminc控制器.
QQ:让index.php默认加载Home模块的Index控制器;而让admin.php默认去加载Admin模块的Adminc控制器.AA:复制index.php命名为admin.php复制(新建)A ...
- 列出当前ARM开发板系统加载的模块
lsmod 列出当前系统中加载的模块,其中左边第一列是模块名,第二列是该模块大小,第三列则是使用该模块的对象数目
- PHP无法加载MySQL模块
在 将PHP根目录下libmysql.dll复制到c:\Windows\system32中 在Apache目录中的conf\httpd.conf 中加载libmysql.dll ...
随机推荐
- php的switch函数
PHP Switch 语句 PHP If...Else PHP While 循环 switch 语句用于基于不同条件执行不同动作. Switch 语句 如果您希望有选择地执行若干代码块之一,请使用 S ...
- Spring-data-redis 第一天
1.Redis 这就不必哆嗦了,Redis 支持丰富的数据类型,String ,List,Sets ,Sorted Sets,Hashes,这就可以看出Java 操作Redis就要针对各种类型都有自己 ...
- 如何求ArrayList集合的交集 并集 差集 去重复并集
需要用到List接口中定义的几个方法: addAll(Collection<? extends E> c) :按指定集合的Iterator返回的顺序将指定集合中的所有元素追加到此列表的末尾 ...
- Zookeeper(四))持久化日志文件
Zookeeper(四))持久化日志文件 持久化用途 存储两种文件 snapshot:内存快照 log:事务日志,类似MySQL的binlog,存储数据节点的操作日志 问题 序列化的本质其实就是将原数 ...
- python3笔记十五:python函数
一:学习内容 函数概述 函数的参数与返回值 参数值传递和引用传递 关键字参数 默认参数 不定长参数 二:函数概述 1.本质:函数就是对功能的封装 2.优点: 简化代码结构,增加了代码的复用度(重复使用 ...
- docker—tomcat 报错:Failed to get D-Bus connection: Operation not permitted
docker search centos 查系统镜像 docker pull docker.io/centos 进入容器 [root@git opt]# docker images REPOSIT ...
- linux上的syslog
在centos上,syslog其实是rsyslog,对应的配置文件为/etc/rsyslog.conf,守护进程为:/etc/rsyslog.d --------------------------- ...
- SQLServer2012R2部署手册
1. 安装软件.net framework3.5 1.在安装SQL SERVER 2012前需要3.5的支持.在WIN 2012系统可以在系统管理的添加角色和功能中安装,如下将[.NET Framew ...
- xstream解析xml时遇到特殊字符出错
在xml中有"&"符号时,解析xml出错 解决办法: 将&替换成&
- 第五周作业,LVM和TCP
1.磁盘lvm管理,完成下面要求,并写出详细过程: 1) 创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv; ...