Why WPF binding handles INotifyPropertyChanged in two different ways?

大城市里の小女人 提交于 2019-12-05 17:13:50

问题


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.

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

  • setter call started
  • value set
  • INotifyPropertyChanged started
  • INotifyPropertyChanged done
  • setter done
  • getter called and done
  • IDataErrorInfo called and done

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

  • setter call started
  • value set
  • INotifyPropertyChanged started
  • getter called and done
  • IDataErrorInfo called and done
  • INotifyPropertyChanged done
  • setter done

回答1:


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.

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



来源:https://stackoverflow.com/questions/10947380/why-wpf-binding-handles-inotifypropertychanged-in-two-different-ways

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!