为什么WPF绑定句柄两种不同的方式INotifyPropertyChanged的? [英] Why WPF binding handles INotifyPropertyChanged in two different ways?

查看:159
本文介绍了为什么WPF绑定句柄两种不同的方式INotifyPropertyChanged的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现,在WPF两种不同的方式处理INotifyPropertyChanged的。我只是想知道是什么原因。

I recently find out that wpf handles INotifyPropertyChanged in two different ways. I just wanna know what's the reason.

让我们以一个正常的双向验证与真实的结合。

Let us take a normal twoway binding with validation true.

如果您设置UI一个属性视图模型它是这样的。

if you set a property from ui to viewmodel it goes like this.


  • 二传手通话开始

  • 设置值

  • INotifyPropertyChanged的启动

  • INotifyPropertyChanged的完成

  • 二传手做

  • 的getter调用,完成

  • IDataErrorInfo的调用,完成

但如果你在你的视图模型设置属性它是这样的。

but if you set the property in your viewmodel it goes like this


  • 二传手通话开始

  • 设置值

  • INotifyPropertyChanged的启动

  • 的getter调用,完成

  • IDataErrorInfo的调用,完成

  • INotifyPropertyChanged的完成

  • 二传手做

推荐答案

改变从UI属性视图模型可能会导致死锁的一种情况可能碰​​上双向场景年末减少递归调用。为了阻止这种情况发生,当WPF正在改变模式,将继续追踪通过INotifyPropertyChanged的变化,但这种变化将在调度程序队列中排队,而其目前的更新完成后,它会被执行。

Changing property from UI to ViewModel may lead to deadlock kind of situation which might run into end less recursive calls in two way scenarios. In order to block this from happening, when WPF is making change to model, it will continue to track changes via INotifyPropertyChanged ,but this change will be queued in dispatcher queue, and it will be executed after its current update is finished.

由于视图模型的变化不是由WPF发起,WPF将不排队的操作,它会立即执行更改。

Since the change in viewmodel is not initiated by WPF, WPF will not queue the operation, it will immediately execute the change.

这篇关于为什么WPF绑定句柄两种不同的方式INotifyPropertyChanged的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆