首页 技术 正文
技术 2022年11月15日
0 收藏 344 点赞 5,032 浏览 2240 个字

一个基本的例子,没有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 SILVERLIGHTApp.Current.RootVisual = (Shell)this.Shell;#elseApp.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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844