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>();}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/51758.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

求职Leetcode题目(9)

1.通配符匹配 题解&#xff1a; 其中&#xff0c;横轴为string s&#xff0c;纵轴为pattern p 这个表第(m,n)个格子的意义是:【p从0位置到m位置】这一整段&#xff0c;是否能与【s从0位置到n位置】这一整段匹配 也就是说&#xff0c;如果表格的下面这一个位置储存的是T(True)…

shell脚本--正则表达式

一、正则表达式的类型 在Linux中,有两种流行的正则表达式引擎: POSIX基础正则表达式(basic regular expression,BRE)引擎 POSIX扩展正则表达式(extended regular expression,ERE)引擎 POSIX BRE引擎通常出现在依赖正则表达式进行文本过滤的编程语言中。它为常见模式提供…

pytorch交叉熵损失函数

nn.CrossEntropyLoss 是 PyTorch 中非常常用的损失函数,特别适用于分类任务。它结合了 nn.LogSoftmax 和 nn.NLLLoss(负对数似然损失)的功能,可以直接处理未经过 softmax 的 logits 输出,计算预测值与真实标签之间的交叉熵损失。 1. 交叉熵损失的原理 交叉熵损失衡量的是…

cnocr 安装

打开终端 如果不会打开终端 -> 终端打开输入 pip install cnocr 执行中途可能报错 去这里下载工具&#xff1a;c构建工具下载完打开&#xff0c;勾选这个 然后点安装安装完回到第2步重新执行

等保2.0--安全计算环境--TiDB数据库

在使用本博客提供的学习笔记及相关内容时,请注意以下免责声明:信息准确性:本博客的内容是基于作者的个人理解和经验,尽力确保信息的准确性和时效性,但不保证所有信息都完全正确或最新。非专业建议:博客中的内容仅供参考,不能替代专业人士的意见和建议。在做出任何重要决…

移动端前端开发主流框架及其技术方案

移动端前端开发主流框架及其技术方案 在现代移动端应用开发中&#xff0c;前端框架的选择至关重要。它不仅影响开发效率&#xff0c;还直接关系到应用的性能和用户体验。以下是当前主流的移动端前端框架的详细技术方案&#xff0c;包括 React Native、Flutter 和 Ionic&#x…

PyTorch 的自动求导与计算图

在深度学习中&#xff0c;模型的训练过程本质上是通过梯度下降算法不断优化损失函数。为了高效地计算梯度&#xff0c;PyTorch 提供了强大的自动求导机制&#xff0c;这一机制依赖于“计算图”&#xff08;Computational Graph&#xff09;的概念。 1. 什么是计算图&#xff1…

前胡基因组与伞形科香豆素的进化-文献精读42

The gradual establishment of complex coumarin biosynthetic pathway in Apiaceae 伞形科中复杂香豆素生物合成途径的逐步建立 羌活基因组--文献精读-36 摘要&#xff1a;复杂香豆素&#xff08;CCs&#xff09;是伞形科植物中的特征性代谢产物&#xff0c;具有重要的药用价…

深度学习与大模型第1课环境搭建

深度学习与大模型第1课 环境搭建 1. 安装 Anaconda 首先&#xff0c;您需要安装 Anaconda&#xff0c;这是一个开源的 Python 发行版&#xff0c;能够简化包管理和环境管理。以下是下载链接及提取码&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1Na2xOFpBXQMgzXA…

网络准入控制系统

当我们谈论网络准入控制系统时&#xff0c;我们谈论的并不是网络准入控制系统&#xff0c;而是安全&#xff0c;我们不能只囿于它表面的浮华而忘掉它的本质&#xff0c;记住&#xff0c;不管讨论什么&#xff0c;我们必须要有直达本质的能力。网络的本质就是安全。 网络准入控制…

TDesign 微信小程序组件库配置

文章目录 1.安装 npm 包2. 构建 npm3. 构建完成后即可使用 npm 包。4.修改 app.json5.修改 tsconfig.json6.使用组件 1.安装 npm 包 在小程序 package.json 所在的目录中执行命令安装 npm 包&#xff1a; npm install结果报错 PS C:\WeChatProjects\miniprogram-1> npm i…

vscode和edge浏览器等鼠标输入光标变透明

本人是AMD的APU会出现这种情况。它的gpu加速有些问题。 都是要关闭gpu硬件加速功能。edge浏览器好找。vscode是通过以下方法。 要关闭VSCode的硬件加速功能&#xff0c; ‌通过配置文件调整‌&#xff1a; 打开VSCode的设置&#xff08;通过按下CtrlShiftP或CmdShiftP打开命令…

【Qt】窗口概述

Qt 窗口概述 Qt窗口是由QMianWindow类来实现的。 QMainWindow 是⼀个为⽤⼾提供主窗⼝程序的类&#xff0c;继承⾃ QWidget 类&#xff0c;并且提供了⼀个预定义的布局。QMainWindow 包含 ⼀个菜单栏&#xff08;menu bar&#xff09;、多个⼯具栏(tool bars)、多个浮动窗⼝&a…

安全入门day.03

一、知识点 1、抓包技术应用意义 在渗透安全方面&#xff0c;通过抓包分析&#xff0c;安全人员可以模拟黑客的攻击行为&#xff0c;对系统进行渗透测试。这种测试有助于发现系统中存在的安全漏洞和弱点。一旦发现漏洞&#xff0c;可以立即采取措施进行修复&#xff0c;从而增…

分享8个Python自动化实战脚本!

1. Python自动化实战脚本 1.1 网络自动化 网络上有丰富的信息资源&#xff0c;Python可以帮我们自动化获取这些信息。 爬虫简介&#xff1a;爬虫是一种自动提取网页信息的程序。Python有许多优秀的爬虫库&#xff0c;如requests和BeautifulSoup。 案例&#xff1a;使用Pytho…

8.26 T4 日记和编辑器(fhq维护kmp——kmp本身含有的单射与可合并性)

http://cplusoj.com/d/senior/p/NOD2301D 前4个操作拿fhq treap是很好维护的。 对于最后一个操作&#xff0c;我们可以这么思考&#xff0c;从kmp的匹配思路出发&#xff1a; 如果我们知道一个串进入的指针 j j j&#xff08;也就是kmp匹配到的位置&#xff09;&#xff0c…

IT 行业的就业情况

当前&#xff0c;IT 行业的就业情况呈现出以下特点&#xff1a; 1. 需求持续增长&#xff1a;随着数字化转型的加速&#xff0c;各个行业对信息技术的依赖程度不断提高&#xff0c;推动了对 IT 人才的持续需求。特别是在云计算、大数据、人工智能、物联网等新兴领域&#xff…

MySQL:复合查询

MySQL&#xff1a;复合查询 聚合统计分组聚合统计group byhaving 多表查询自连接子查询单行子查询多行子查询多列子查询from子查询 合并查询unionunion all 内连接外连接左外连接右外连接全外连接 视图 MySQL 复合查询是数据分析和统计的强大工具&#xff0c;本博客将介绍如何使…

【WiFi主要技术学习2】

WiFi协议学习2 WiFi SPEC理解频段信道带宽协商速率安全与加密WiFi主要技术理解BP直接序列扩频(Direct Sequence Spread Spectrum,DSSS)BPSKQPSK正交幅度调制(Quadrature Amplitude Modulation,QAM)互补码键控(Complementary Code Keying,CCK)正交频分复用(Orthogonal…

Global Illumination_LPV Deep Optimizations

接上回&#xff0c;RSM优化技术介绍后&#xff0c;我们本部分主要看一下&#xff0c;光栅GI三部曲中的LPV&#xff0c;这个算法算是很巧妙了&#xff0c;算法思路基于RSM上拓展到世界空间&#xff0c;可以说很具学习和思考价值&#xff0c;之前也简单实现过Global Illumination…