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

推荐订阅源

N
News and Events Feed by Topic
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
Jina AI
Jina AI
H
Help Net Security
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
L
LangChain Blog
Recorded Future
Recorded Future
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
GbyAI
GbyAI
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
M
MIT News - Artificial intelligence
爱范儿
爱范儿
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
B
Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
MongoDB | Blog
MongoDB | Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
The Cloudflare Blog
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
D
DataBreaches.Net
博客园 - 【当耐特】
T
Troy Hunt's Blog
V
Visual Studio Blog
V2EX - 技术
V2EX - 技术
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
The GitHub Blog
The GitHub Blog

博客园 - 天涯

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 中及其的方便。