所谓的潇洒

导航

Module

1.模块加载方式:配置文件、代码、xmal

2.配置文件加载模块

  1>创建模块,并在模块初始化方法中添加如下代码  

        public void OnInitialized(IContainerProvider containerProvider)
        {
            var registerManager = containerProvider.Resolve<IRegionManager>();
            registerManager.RegisterViewWithRegion("ContentRegion", typeof(ViewA));
        }

  2>在主程序中添加如下配置文件  

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="modules" type="Prism.Modularity.ModulesConfigurationSection,Prism.Wpf"/>
    </configSections>
    <modules>
        <module assemblyFile="Module1.dll" moduleType="Module1.Module1Module,Module1,Version=1.0.0.0,Culture=neutral,PublickeyTocken=null"
                moduleName="Module1Module" startupLoaded="True"/>
    </modules>
</configuration>

  3>主程序的主窗体xaml中添加如下代码

  <ContentControl prism:RegionManager.RegionName="ContentRegion"/>

  4>生成模块dll,放入主程序执行目录

3.视图注入  

        public void OnInitialized(IContainerProvider containerProvider)
        {
            var registerManager = containerProvider.Resolve<IRegionManager>();
            var region = registerManager.Regions["ContentRegion"];
            region.RequestNavigate("ViewA");
        }

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<ViewA>();
        }

 

posted on 2023-03-19 17:42  所谓的潇洒  阅读(180)  评论(0编辑  收藏  举报