日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

WPF Prism框架介绍

發(fā)布時間:2023/12/14 asp.net 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPF Prism框架介绍 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

WPF Prism (一) Region
WPF Prism(二)Module
WPF Prism(三)ViewModelLocator
WPF Prism(四)MVVM
WPF Prism(五)Navigation
WPF Prism(六)Dialog

一、什么是Prism

Prism是一個用于在 WPF、Xamarin Form、Uno 平臺和 WinUI 中構建松散耦合、可維護和可測試的 XAML 應用程序框架。

二、官方地址

https://github.com/PrismLibrary/Prism

基于Prism的VisualStudio擴展包模板: Prism Template Pack,下載它后可以快速創(chuàng)建基于Prism的項目。

三、Prism框架內容

框架中包括 MVVM、依賴注入、Command、Message Event、導航、彈窗等功能。

四、Prism知識章節(jié)

  • 1.Region(區(qū)域管理)
  • 2.Module(模塊)
  • 3.View Injection(視圖注入)
  • 4.ViewModelLocationProvider(視圖模型定位)
  • 5.Command(綁定相關)
  • 6.Eevent Aggregator (事件聚合器)
  • 7.Navigation(導航)
  • 8.Dialog(對話框)

五、創(chuàng)建一個Prism應用程序

1、安裝VS拓展包:Prism Template Pack(已有則不需要安裝)。

2、添加新項目并選擇項目模板:Prism Blank App(.NET Core)。

3、項目創(chuàng)建過程中會讓你選擇一個容器,我們選擇了Unity容器,具體使用可以https://blog.csdn.net/zhudaokuan/article/details/111227077。

4、這樣一個空白的.NET Core Prism WPF項目就創(chuàng)建成功了。

那么我們來看看它到底有什么不一樣的地方。

5、首先查看App.xaml和App.xaml.cs文件

<prism:PrismApplicationx:Class="PrismBlankAppCore.App"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="clr-namespace:PrismBlankAppCore"xmlns:prism="http://prismlibrary.com/"><Application.Resources /> </prism:PrismApplication> public partial class App{protected override Window CreateShell(){return Container.Resolve<MainWindow>();}protected override void RegisterTypes(IContainerRegistry containerRegistry){}}

在App.xaml文件中,原先的Application類替換為了prism:PrismApplication,但同樣的它們都是App的部分類。那PrismApplication和Application有什么關系呢?

#mermaid-svg-gXA0uYitoD3iscW3 {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-gXA0uYitoD3iscW3 .error-icon{fill:#552222;}#mermaid-svg-gXA0uYitoD3iscW3 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-gXA0uYitoD3iscW3 .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-gXA0uYitoD3iscW3 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-gXA0uYitoD3iscW3 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-gXA0uYitoD3iscW3 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-gXA0uYitoD3iscW3 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-gXA0uYitoD3iscW3 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-gXA0uYitoD3iscW3 .marker.cross{stroke:#333333;}#mermaid-svg-gXA0uYitoD3iscW3 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-gXA0uYitoD3iscW3 g.classGroup text{fill:#9370DB;fill:#131300;stroke:none;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:10px;}#mermaid-svg-gXA0uYitoD3iscW3 g.classGroup text .title{font-weight:bolder;}#mermaid-svg-gXA0uYitoD3iscW3 .nodeLabel,#mermaid-svg-gXA0uYitoD3iscW3 .edgeLabel{color:#131300;}#mermaid-svg-gXA0uYitoD3iscW3 .edgeLabel .label rect{fill:#ECECFF;}#mermaid-svg-gXA0uYitoD3iscW3 .label text{fill:#131300;}#mermaid-svg-gXA0uYitoD3iscW3 .edgeLabel .label span{background:#ECECFF;}#mermaid-svg-gXA0uYitoD3iscW3 .classTitle{font-weight:bolder;}#mermaid-svg-gXA0uYitoD3iscW3 .node rect,#mermaid-svg-gXA0uYitoD3iscW3 .node circle,#mermaid-svg-gXA0uYitoD3iscW3 .node ellipse,#mermaid-svg-gXA0uYitoD3iscW3 .node polygon,#mermaid-svg-gXA0uYitoD3iscW3 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-gXA0uYitoD3iscW3 .divider{stroke:#9370DB;stroke:1;}#mermaid-svg-gXA0uYitoD3iscW3 g.clickable{cursor:pointer;}#mermaid-svg-gXA0uYitoD3iscW3 g.classGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-svg-gXA0uYitoD3iscW3 g.classGroup line{stroke:#9370DB;stroke-width:1;}#mermaid-svg-gXA0uYitoD3iscW3 .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-svg-gXA0uYitoD3iscW3 .classLabel .label{fill:#9370DB;font-size:10px;}#mermaid-svg-gXA0uYitoD3iscW3 .relation{stroke:#333333;stroke-width:1;fill:none;}#mermaid-svg-gXA0uYitoD3iscW3 .dashed-line{stroke-dasharray:3;}#mermaid-svg-gXA0uYitoD3iscW3 #compositionStart,#mermaid-svg-gXA0uYitoD3iscW3 .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gXA0uYitoD3iscW3 #compositionEnd,#mermaid-svg-gXA0uYitoD3iscW3 .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gXA0uYitoD3iscW3 #dependencyStart,#mermaid-svg-gXA0uYitoD3iscW3 .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gXA0uYitoD3iscW3 #dependencyStart,#mermaid-svg-gXA0uYitoD3iscW3 .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gXA0uYitoD3iscW3 #extensionStart,#mermaid-svg-gXA0uYitoD3iscW3 .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gXA0uYitoD3iscW3 #extensionEnd,#mermaid-svg-gXA0uYitoD3iscW3 .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gXA0uYitoD3iscW3 #aggregationStart,#mermaid-svg-gXA0uYitoD3iscW3 .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gXA0uYitoD3iscW3 #aggregationEnd,#mermaid-svg-gXA0uYitoD3iscW3 .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gXA0uYitoD3iscW3 .edgeTerminals{font-size:11px;}#mermaid-svg-gXA0uYitoD3iscW3 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}ApplictionPrismApplicationBase+IContainerProvider Container+Window CreateShell()PrismApplication

PrismApplictionBase抽象類中有幾個重要的屬性和方法:

  • IContainerProvider Container只讀屬性:Unity容器對象,可以用來創(chuàng)建對象。
  • abstract RegisterTypes(IContainerRegistry containerRegistry)抽象方法:可以用來給容器中注冊對象。
  • abstract Window CreateShell()抽象方法:用來創(chuàng)建主窗體。

try containerRegistry)抽象方法:可以用來給容器中注冊對象。

  • abstract Window CreateShell()抽象方法:用來創(chuàng)建主窗體。

所以我們可以看到在App類中,已經重寫了CreateShell()方法和RegisterTypes()方法。還有一點值得一提,在App.xaml文件中,我們沒有設置StartupUri,這是因為我們重寫了CreateShell()方法,并在方法中使用容器創(chuàng)建了主窗體。

六 Demo

Demo持續(xù)更新中

總結

以上是生活随笔為你收集整理的WPF Prism框架介绍的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。