惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 天涯

Prism.Interactivity 和 Prism.Modularity 介绍 对 mvvm 架构的理解 wpf mvvm 架构 C#硬件开发业务流程调试技巧 wpf winform 截图 wpf Cannot locate resource 'app.xaml' app.config ConfigSection 保护 程序开发注意4项,你知道吗? .net 变量缓存,你知道吗 wpf 多线程 更新UI 界面 wpf treeview 绑定不同的对象 .net 技术,你掌握了多少 aspx 中确认删除 脚本 - 天涯 .net 中对类的扩展 奇怪--ORA-12154:TNS:无法处理服务名: 建模十条原则 由软件加壳谈起 Hashtable 应注意的 2 点 vb 调用c#做的com 组件
Prism BindableBase 和 Commands 的介绍
天涯 · 2020-07-26 · via 博客园 - 天涯

Prism.Mvvm: 主要包含 BindableBase 实现数据字段绑定,并有更新通知。

建议先建个基类继承 BindableBase ,然后其他类继承基类,及方便以后有公共属性或方法的使用,也可以方便替换 Prism.Mvvm .

代码例子如下:

  public  class BaseModelView: BindableBase

{

   ….

  private bool _isValid=true;

        public  bool IsValid

        {

            get

            {            

                return _isValid ;

            }

            set

            {

                if (value != _isValid)

                {

                    _isValid = value;

                    this.RaisePropertyChanged("IsValid");

                }

            }

        }

}

  Prism.Commands: 主要包含 DelegateCommand, CompositeCommand 。DelegateCommand 主要和  Command 配合使用。Command 可以绑定定义好的 DelegateCommand 。

DelegateCommand 定义如下:

方式1:

  public ICommand ClickCmd

        {

            get {

                return new DelegateCommand(() =>

                {

                    ……

                });

            }

        }

方式2:

public DelegateCommand<object> SubmitCommand { get; private set; }

this.SubmitCommand = new DelegateCommand<object>(this.Submit, this.CanSubmit);

  private void Submit(object parameter)

        {

// 方法体

}

private bool CanSubmit(object parameter)

        {

            Return true;

        }

  这是主要的方法定义

CompositeCommand:就是将多个 DelegateCommand 组合到一起调用:

private readonly CompositeCommand saveAllCommand;

public DelegateCommand<object> SaveProductsCommand { get; private set; }

public DelegateCommand<object> SaveOrdersCommand { get; private set; }

this.saveAllCommand = new CompositeCommand();         this.saveAllCommand.RegisterCommand(SaveProductsCommand);         this.saveAllCommand.RegisterCommand(SaveOrdersCommand);

有注册事件,就有取消事件:

saveAllCommand.UnregisterCommand(cmd);

 理解了 BindableBase 和 Command 就可以在小型的项目中使用 Prism.mvvm 了,就可以体会到数据绑定在wpf 中及其的方便。