一个基本的例子,没有viewmodel,没有使用Behaviors

大体步骤:

1、创建应用程序

2、使用"Shell"替换"MainWindow"(silverlight替换MainPage)

3、创建Bootstrapper(引导程序)

4、创建模块

5、加入视图

1、创建程序

使用vs 2010创建wpf或silverlight应用程序,添加以下引用

Microsoft.Practices.Prism

Microsoft.Practices.Prism.MefExtensions

System.ComponentModel.Composition

2、修改MainWindow.cs或MainPage.cs为Shell.cs

在代码视图中,右键点MainWindow或MainPage选择重构--〉重命名,命名为Shell

修改App.xaml

wpf程序去掉starturi属性

修改App.xaml.cs

Startup事件中

 private void Application_Startup(object sender, StartupEventArgs e)

{

Bootstrapper bootstrapper = new Bootstrapper();

bootstrapper.Run();

}

导出Shell

 [Export]

public partial class Shell : Window

{

public Shell()

{

InitializeComponent();

}

}

3、创建Bootstrapper

添加Bootstrapper类,注意wpf/silverlight在InitializeShell中的区别


using Microsoft.Practices.Prism.MefExtensions;

using System.ComponentModel.Composition.Hosting;

using System.IO;

namespace WpfApplication

{

class Bootstrapper : MefBootstrapper

{

protected override System.Windows.DependencyObject CreateShell()

{

return this.Container.GetExportedValue<Shell>();

}

protected override void InitializeShell()

{

base.InitializeShell();

#if SILVERLIGHT

App.Current.RootVisual = (Shell)this.Shell;

#else

App.Current.MainWindow = (Shell)this.Shell;

App.Current.MainWindow.Show();

#endif

}

protected override void ConfigureAggregateCatalog()

{

base.ConfigureAggregateCatalog();

//加载自身

this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(this.GetType().Assembly));

//加载目录

if (Directory.Exists("./Modules"))

{

this.AggregateCatalog.Catalogs.Add(new DirectoryCatalog("./Modules"));

}

}

}

}

4、创建模块

加入以下引用

Microsoft.Practices.Prism

Microsoft.Practices.Prism.MefExtensions

System.ComponentModel.Composition

加入模块初始化用的类如:MarketModule,实现Initialize

 [ModuleExport(typeof(MarketModule))]

public class MarketModule: IModule

{

[Import]

public IRegionManager TheRegionManager { private get; set; }

public void Initialize()

{

TheRegionManager.RegisterViewWithRegion("MarketRegion", typeof(MarketView));

}

}

5、加入视图,并导出

 [Export(typeof(MarketView))]

public partial class MarketView : UserControl

{

public MarketView()

{

InitializeComponent();

}

}

6、修改Shell.xaml

加入prism命名空间

xmlns:prism="http://www.codeplex.com/prism"

Grid中加入

<ItemsControl prism:RegionManager.RegionName="MarketRegion"/>

7、应用程序中创建文件夹Modules

在Modules文件中,加入现有项(以链接方式)"模块名称.dll" 如Modules.Market.dll

模块名称.dll,复制到目录属性选择"始终复制"或"如果较新则复制"

转载:http://www.cnblogs.com/ningth/archive/2011/12/04/2275133.html

最新文章

  1. NoSql数据库使用半年后在设计上面的一些心得
  2. linux Mint 安装tomcat8
  3. BHP Net Tool
  4. 《理解 ES6》阅读整理:函数(Functions)(一)Default Parameter Values
  5. [转载]C# ListView用法详解
  6. 【09】绝不在构造和析构过程中调用virtual方法
  7. C#中数据源绑定DataSource以及相关控件(DataGridView)的使用总结
  8. IIS环境下部署项目
  9. [技术]浅谈c++ this指针
  10. Signed Distance Field Shadow in Unity
  11. Jenkins-Pipeline 流水线发布部署项目
  12. zabbix 在图形中显示网络设备的接口描述
  13. 进程池和线程池 concurrent.futures import ProcessPoolExecutor,ThreadPoolExecutor
  14. 网络基础协议part 1
  15. 协议无关组播-密集模式 PIM-DM
  16. &lt;转载&gt;ant使用指南详细入门教程 http://www.jb51.net/article/67041.htm
  17. 实用SQL大全
  18. php代码编写
  19. 用shell 实现对MySQL数据库分页
  20. Unity3D笔记十九 持久化数据

热门文章

  1. Eclipse界面设置与常用技巧
  2. PHP数据的序列化/反序列化
  3. Spring AOP 动态代理 缓存
  4. 关于字符串查找 charindex ,Patindex 还有一个like
  5. JS实现别踩白块小游戏
  6. Linux文件I/O
  7. 配置安装DVWA
  8. html5语法
  9. 有时候就是看不进论文-jQuery动画特效篇&amp;MySQL
  10. Caffe源码解析1:Blob