01前言
目前最新的PRISM的版本是8.1.97,本节以6.3.0.0 讲解,可以在Github上获取PRISM的源码。
Prism要用到IOC容器,提供选择的有Unity和MEF,这里我分别采用MEF和unity去做。
02安装库
在nuget上安装Prism相关常用的库
03项目搭建
step1:新建解决方案:我这里命名为PrismFrameTest;
step2:删除MainWindow.xaml,删除App.xaml中启动引导
StartupUri="MainWindow.xaml"
然后在App.xaml.cs新建程序入口
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
MyBootstrapper bootStrapper = new MyBootstrapper();
bootStrapper.Run(true);
}
新建引导类MyBootstrapper.cs,需要继承基类Prism.Mef库下的基类MefBootstrapper
方式1 采用mef
public class MyBootstrapper : MefBootstrapper
{
protected override DependencyObject CreateShell()
{
return this.Container.GetExportedValue<MyShellView>();
}
protected override void InitializeShell()
{
base.InitializeShell();
Application.Current.MainWindow = (MyShellView)this.Shell;
Application.Current.MainWindow.Show();//Show主窗口,但conten