wpf prism加载独立模块实例

摘要:
1、 首先,查看生成dll的文件模块1模块2的组织结构。

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

wpf prism加载独立模块实例第1张

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加载独立模块实例第2张

免责声明:文章转载自《wpf prism加载独立模块实例》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇[转载]ERwin相关概念入门C# HttpWebRequest请求服务器(Get/Post兼容)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

WPF 解决文本框设置了阴影效果后,因左右的transform变化引发的拉伸渲染问题

背景 最近遇到一个动画执行时,文本位置变化的问题。如下图: 如果你仔细看的话,当星星变小时,文本往下降了几个像素。 貌似有点莫名其妙,因为控件之间并不在同一个Panel布局控件中,不存在高度限制变化引发此类问题。所以有了如下测试 测试场景 字体类型影响 1. 首先新建了一个空项目,前面是一个带阴影的文本,后面用一张普通图片循环变更它的高度。尝试了下,还是...

WPF基于Live Charts实现波形图

using LiveCharts;//livecharts.netusing LiveCharts.Wpf;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threadi...

WPF双向绑定

数据绑定模式共有四种:OneTime、OneWay、OneWayToSource和TwoWay,默认是TwoWay。 TwoWay 当发生更改时的目标属性或源属性更新目标属性。OneWay 仅当源属性更改时,请更新目标属性。OneTime 仅当应用程序启动时或时,请更新目标属性DataContext发生了更改。OneWayToSource 目标属性更改时,...

WPF MVVM模式

什么是MVVM模式,Model(模型)-View(视图)-ViewModel(视图模型) 先来讲MVC模式,模型-视图-控制器,相信大多数人都用过原理无非是: 页面产生某个请求,先找到页面对应的控制器,然后触发控制器的方法,控制器去模型调取数据拿回来,再返回给相应的视图,最后呈现页面。 MVVM模式原理类似MVC,只不过中间的不叫控制器了叫视图模型,功能也...

.NET 控件集 ComponentOne V2020.0 Update3 发布,正式支持 .NET 5

ComponentOne 是一套专注于企业 .NET开发、支持 .NET Core 平台,并完美集成于 Visual Studio 的第三方控件集,包含 300 多种 .NET开发控件,可满足 WinForm、WPF、 UWP、ASP.NET MVC等七个 .NET平台的系统开发需求,并提供表格数据管理、数据可视化、报表、输入和编辑等七大功能,被誉为“.NE...

WPF 制作圆角按钮

在程序对应坐置插入以下代码,或是先拖一个按钮控件到窗体中,再替换对应的代码。 修改CornerRadius="18,3,18,3" 就可以改变圆角大小 按钮效果: <Button Content="Button" HorizontalAlignment="Left" Margin="19,10,0,0" VerticalAlignment="Top...