当前位置: 首页 > news >正文

wpf prism 《1》、区域 、模块化

安装prism.DryIoc

在这里插入图片描述

修改app.xaml

在这里插入图片描述

<prism:PrismApplication x:Class="WpfApp3.App"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="clr-namespace:WpfApp3"xmlns:prism="http://prismlibrary.com/"><Application.Resources></Application.Resources>
</prism:PrismApplication>

在这里插入图片描述

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : PrismApplication
{protected override Window CreateShell(){return Container.Resolve<MainWindow>();}protected override void RegisterTypes(IContainerRegistry containerRegistry){//throw new NotImplementedException();}
}
安装 模板 prism Template pack

在这里插入图片描述
在这里插入图片描述

DirectoryModuleCatalog、XamlModuleCatalog、ConfigurationModuleCatalog 都间接继承IModuleCatalog

在这里插入图片描述

Prism 区域

在这里插入图片描述
在这里插入图片描述
》》 prism:ViewModelLocator.AutoWireViewModel=“True”,
》》View要和ViewModel自带匹配,不需要 this.DataContext = new ViewModel();
》》需要遵循一个些规定, ViewModels 中的View名称+ViewModel 这种命名规则

<Window x:Class="BlankApp2.Views.MainView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:prism="http://prismlibrary.com/"prism:ViewModelLocator.AutoWireViewModel="True"Title="{Binding Title}" Height="350" Width="525" ><Grid><Grid.RowDefinitions><RowDefinition Height="50"></RowDefinition><RowDefinition></RowDefinition></Grid.RowDefinitions><StackPanel Orientation="Horizontal" HorizontalAlignment="Right"><Button Content="模块A" Command="{Binding OpenCommand}" CommandParameter="ViewA"></Button><Button Content="模块B" Command="{Binding OpenCommand}" CommandParameter="ViewB"></Button></StackPanel><ContentControl Grid.Row="1" prism:RegionManager.RegionName="ContentRegion" /></Grid>
</Window>
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;namespace BlankApp2.ViewModels
{public class MainViewModel : BindableBase{private string _title = "Prism Application";public string Title{get { return _title; }set { SetProperty(ref _title, value); }}private readonly IRegionManager _regionManager;public MainViewModel(IRegionManager regionManager){this._regionManager = regionManager;this.OpenCommand = new DelegateCommand<string>(Open);}private void Open(string obj){_regionManager.Regions["ContentRegion"].RequestNavigate(obj);}public  DelegateCommand<string> OpenCommand { get; private set; }}
}
using BlankApp2.Views;
using Prism.Ioc;
using System.Windows;namespace BlankApp2
{/// <summary>/// Interaction logic for App.xaml/// </summary>public partial class App{protected override Window CreateShell(){return Container.Resolve<MainView>();}protected override void RegisterTypes(IContainerRegistry containerRegistry){containerRegistry.RegisterForNavigation<ViewA>();           containerRegistry.RegisterForNavigation<ViewB>();//可以不使用默认匹配规则,自己指定对应的上下文//containerRegistry.RegisterForNavigation<ViewA,ViewAViewModel>();//containerRegistry.RegisterForNavigation<ViewA,ViewBViewModel>();}}
}

模块化 《1》 强引用

在这里插入图片描述
》》》通过prism Blank APP WPF 创建一个wpf应用
在这里插入图片描述
在这里插入图片描述
》》》新建模块步骤

  1. 新建wpf应用程序
  2. nugut 》》Prism.DryIoc
  3. 删除 App.xaml AssembylyInfo.cs MainWindow.xaml 这三个文件,同时把项目修改 类库
  4. 新建Views 文件夹 存放 视图文件
  5. 新建一个 项目名称+Profile 命名的 类

在这里插入图片描述
在这里插入图片描述

using ModuleA.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ModuleA
{public class ModuleAProfile : IModule{public void OnInitialized(IContainerProvider containerProvider){// throw new NotImplementedException();}public void RegisterTypes(IContainerRegistry containerRegistry){//ViewA  是Views下面的 视图文件containerRegistry.RegisterForNavigation<ViewA>();}}
}

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
需要在主程序 引用模块
在这里插入图片描述

在这里插入图片描述

模块化 《2》 利用目录,不需要引用这些模块的dll,上面的方式需要引用dll

在这里插入图片描述

using BlankApp2.Views;using Prism.Ioc;
using Prism.Modularity;using System.Windows;namespace BlankApp2
{/// <summary>/// Interaction logic for App.xaml/// </summary>public partial class App{protected override Window CreateShell(){return Container.Resolve<MainView>();}protected override void RegisterTypes(IContainerRegistry containerRegistry){//containerRegistry.RegisterForNavigation<ViewA>();//containerRegistry.RegisterForNavigation<ViewB>();}protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog){//moduleCatalog.AddModule<StudentProfile>();//moduleCatalog.AddModule<ModuleAProfile>();//moduleCatalog.AddModule<ModuleCProfile>();//base.ConfigureModuleCatalog(moduleCatalog);}protected override IModuleCatalog CreateModuleCatalog(){return new DirectoryModuleCatalog() { ModulePath = @".\Modules" };}}
}

在这里插入图片描述

模块化 配置文件的方式可以使用App.config进行配置,也可以使用xml文件的方式。 都需要把模块dll引入

主程序 添加 配置文件app.config

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

在这里插入图片描述

xaml 配置文件

在这里插入图片描述

<m:ModuleCatalog xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:m="clr-namespace:Prism.Modularity;assembly=Prism.Wpf"><m:ModuleInfo ModuleName="ModuleAProfile" ModuleType="ModuleA.ModuleAProfile, ModuleA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /></m:ModuleCatalog>

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

using ModuleA.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ModuleA
{public class ModuleAProfile : IModule{public void OnInitialized(IContainerProvider containerProvider){// throw new NotImplementedException();var regionManager = containerProvider.Resolve<IRegionManager>();regionManager.RegisterViewWithRegion("ContentRegion", typeof(ViewA));}public void RegisterTypes(IContainerRegistry containerRegistry){//containerRegistry.RegisterForNavigation<ViewA>();}}
}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • WPF中使用Echarts显示图表
  • zeppline如何配置用户登陆
  • Python使用zdppy_mysql操作MySQL和MariaDB数据库快速入门教程
  • PE文件结构详解(非常详细)
  • 【Leetcode:2024. 考试的最大困扰度 + 滑动窗口】
  • [易聊]软件项目测试报告
  • Java 面向对象编程的四个基本原则(封装、继承、多态和抽象),并给出一个简单的例子说明如何在 Java 中应用这些原则?
  • Postman中参数填写方式
  • FaceFormer嘴形同步论文复现
  • Web开发
  • 使用Python+docx+jieba+wordcloud给word文档生成词云图
  • Java18 设计模式
  • vue2.0+ts中默认demo组件
  • ubuntu 安装opencv(3.4.16)
  • 【C++二分查找 贪心】1552. 两球之间的磁力
  • 4. 路由到控制器 - Laravel从零开始教程
  • Bytom交易说明(账户管理模式)
  • CentOS7 安装JDK
  • iOS | NSProxy
  • JavaSE小实践1:Java爬取斗图网站的所有表情包
  • jQuery(一)
  • overflow: hidden IE7无效
  • Redis字符串类型内部编码剖析
  • spring boot下thymeleaf全局静态变量配置
  • Spring Cloud中负载均衡器概览
  • Terraform入门 - 3. 变更基础设施
  • 创建一种深思熟虑的文化
  • 如何在GitHub上创建个人博客
  • 什么软件可以提取视频中的音频制作成手机铃声
  • 使用阿里云发布分布式网站,开发时候应该注意什么?
  • 我的业余项目总结
  • 一、python与pycharm的安装
  • 你对linux中grep命令知道多少?
  • 400多位云计算专家和开发者,加入了同一个组织 ...
  • 从如何停掉 Promise 链说起
  • #pragam once 和 #ifndef 预编译头
  • #在线报价接单​再坚持一下 明天是真的周六.出现货 实单来谈
  • #知识分享#笔记#学习方法
  • (12)目标检测_SSD基于pytorch搭建代码
  • (vue)el-cascader级联选择器按勾选的顺序传值,摆脱层级约束
  • (多级缓存)多级缓存
  • (接口自动化)Python3操作MySQL数据库
  • (顺序)容器的好伴侣 --- 容器适配器
  • (学习总结16)C++模版2
  • (转)h264中avc和flv数据的解析
  • (转)http-server应用
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • .h头文件 .lib动态链接库文件 .dll 动态链接库
  • .net core 的缓存方案
  • .NET Core中如何集成RabbitMQ
  • .Net6支持的操作系统版本(.net8已来,你还在用.netframework4.5吗)
  • .net项目IIS、VS 附加进程调试
  • ??javascript里的变量问题
  • [].shift.call( arguments ) 和 [].slice.call( arguments )
  • []Telit UC864E 拨号上网