undefinedundefined

 一.安装Prism

 

1.使用程序包管理控制台#

Install-Package Prism.Unity -Version 7.2.0.1367
也可以去掉‘-Version 7.2.0.1367’获取最新的版本

 2.使用管理解决方案的Nuget包#

 


在上面或许我们有个疑问?为啥安装prism会跟Prism.Unity有关系,我们知道Unity是个IOC容器,而Prism本身就支持IOC,且目前官方支持几种IOC容器:

1.且unity由于是微软官方的,且支持prism的组件化,由此我推荐使用prism.unity,在官方文档中prism7不支持prism.Mef,Prism 7.1将不支持prism.Autofac
2.安装完prism.unity就已经包含着所有prism的核心库了,架构如下:

二.实现数据绑定

我们先创建Views文件夹和ViewModels文件夹,将MainWindow放在Views文件夹下,再在ViewModels文件夹下面创建MainWindowViewModel类,如下:

 

xmal代码如下:
复制代码
<Window x:Class="PrismSample.Views.MainWindow"         xmlns="upload/201911221126125483.gif" alt="复制代码" style="margin: 30px auto; padding: 0px; border: none !important; display: block; border-radius: 3px; max-width: 900px; background-color: transparent !important; height: auto;" />

 

ViewModel代码如下:
复制代码
using Prism.Commands; using Prism.Mvvm;  namespace PrismSample.ViewModels {    public class MainWindowViewModel:BindableBase     {         private string _text;         public string Text         {             get { return _text; }             set { SetProperty(ref _text, value); }         }          private DelegateCommand _clickCommnd;         public DelegateCommand ClickCommnd =>             _clickCommnd ?? (_clickCommnd = new DelegateCommand(ExecuteClickCommnd));          void ExecuteClickCommnd()         {             this.Text = "Click Me!";         }          public MainWindowViewModel()         {             this.Text =