搜索
您的当前位置:首页prism 创建Module

prism 创建Module

来源:飒榕旅游知识分享网

1 根据《prism项目搭建》搭建prism项目

2 在解决方案中新建wpf用户控件库

 3 删除UserControl1.xaml,并通过nuget添加prism.unity框架

4 在库里面新建文件夹Views

5 在Views下面新建用户控件ViewA

<UserControl x:Class="ModuleA.Views.ViewA"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:ModuleA.Views"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <TextBlock Text="View A" FontSize="38" />
    </Grid>
</UserControl>

6 在库里面新建类,让其实现IModule接口

using ModuleA.Views;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Regions;

namespace ModuleA
{
    public class ModuleAModule : IModule
    {
        public void OnInitialized(IContainerProvider containerProvider)
        {
            var regionManager = containerProvider.Resolve<IRegionManager>();
            regionManager.RegisterViewWithRegion("ContentRegion", typeof(ViewA));
        }

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            
        }
    }
}

7 在主项目中引用ModuleA项目

因篇幅问题不能全部显示,请点此查看更多更全内容

Top