二 Prism 环境配置

文章目录

  • 二 Prism 环境配置
    • 1.1 下载和设置Prism
    • 1.2 Nuget 获取Prism
    • 1.3 生产力工具
      • 1.3.1 Visual Studio 安装
      • 1.3.2 快捷代码
      • 1.3.3 项目模板

二 Prism 环境配置

Prism Logo
从上一节中我们了解到 Prism 是一种MVVM框架,那么如何熟悉和使用它呢?

库地址:https://github.com/PrismLibrary
源代码地址:https://github.com/PrismLibrary/Prism
例程地址:https://github.com/PrismLibrary/Prism-Samples-Wpf
文档地址:https://github.com/PrismLibrary/Prism-Documentation
文档网页:https://prismlibrary.com/docs/index.html

1.1 下载和设置Prism

源代码地址:https://github.com/PrismLibrary/Prism

1.2 Nuget 获取Prism

NuGet 上提供了官方 Prism 版本。

一般推荐直接用模板创建即可。

Unity DryIoc 的区别与联系,都是IOC框架,但是DryIoc 性能更加,更推荐使用。

1.3 生产力工具

所谓生产力工具其实就是给Visual Studio 配置 Prism 扩展。配置扩展之后可以有更方便使用Prism的功能。

1.3.1 Visual Studio 安装

Prism 模板包在Visual Studio Gallery中可用。要在 Visual Studio 2019 中安装,只需转到Visual Studio -> Extensions -> ManageExtensions -> Online -> Visual Studio Marketplace在线图库中搜索“Prism Template Pack”:
在这里插入图片描述

1.3.2 快捷代码

Prism 模板包包含用于构建 WPF 和使用 Prism 的 Xamarin.Forms 应用程序的片段、项模板和项目模板的集合。

propp - 具有支持字段的属性,取决于 BindableBase

    private string _fieldName;public string PropertyName{get { return _fieldName; }set { SetProperty(ref _fieldName, value); }}

cmd - 使用 Execute 方法创建 DelegateCommand 属性

    private DelegateCommand _fieldName;public DelegateCommand CommandName =>_fieldName ?? (_fieldName = new DelegateCommand(ExecuteCommandName));void ExecuteCommandName(){}

cmdfull - 使用 Execute 和 CanExecute 方法创建 DelegateCommand 属性

    private DelegateCommand _fieldName;public DelegateCommand CommandName =>_fieldName ?? (_fieldName = new DelegateCommand(ExecuteCommandName, CanExecuteCommandName));void ExecuteCommandName(){}bool CanExecuteCommandName(){return true;}

cmdg - 创建一个通用的 DelegateCommand财产

    private DelegateCommand<string> _fieldName;public DelegateCommand<string> CommandName =>_fieldName ?? (_fieldName = new DelegateCommand<string>(ExecuteCommandName));void ExecuteCommandName(string parameter){}

cmdgfull - 创建一个通用的 DelegateCommand具有 Execute 和 CanExecute 方法的属性

    private DelegateCommand<string> _fieldName;public DelegateCommand<string> CommandName =>_fieldName ?? (_fieldName = new DelegateCommand<string>(ExecuteCommandName, CanExecuteCommandName));void ExecuteCommandName(string parameter){}bool CanExecuteCommandName(string parameter){return true;}

1.3.3 项目模板

WPF Prism Blank App - 这是一个项目模板,本质上是创建一个新的 WPF shell 应用程序。它将有一个基本的引导程序,负责初始化应用程序并显示 shell。它将有一个 MainWindow 和一个 MainWindowViewModel 分别位于 Views 和 ViewModels 文件夹中。
Prism 模块 - 此项目模板将向您的解决方案添加一个新项目,该项目将充当 Prism 模块。它将定义一个实现 IModule 的类,其中包含两个空文件夹用于您的视图和视图模型。
使用新的 WPF 项目向导选择您的容器,不再需要担心引入正确的 Nuget 包。

下一节,准备介绍 依靠官方给的示例程序 Prism-Samples-Wpf 介绍MVVM框架Prism的具体使用方法。


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部