Update ViewModel from View

核能气质少年 提交于 2019-12-13 06:25:55

问题


Is there any event or way to know the trigger when the ViewModel is updating/updated by the View?

INotifyPropertyChanged and PropertyChanged is used when the ViewModel updated the View.

But is there any reverse?


回答1:


Changes from the view to the view model will trigger PropertyChanged as well, as they set properties.




回答2:


If your are binding the controls in your view to the view model, many of the pieces will update the view model as long as you make sure the binding is Mode=TwoWay.

http://msdn.microsoft.com/en-us/library/system.windows.data.bindingmode.aspx

if for some reason you have set your UpdateSourceTrigger in the binding to be Explicit then to update the viewmodel you will need to get the binding expression and call update source

http://msdn.microsoft.com/en-us/library/system.windows.data.bindingoperations.getbindingexpression.aspx




回答3:


If you are using binding then you can use Binding.SourceUpdated and Binding.TargetUpdated Attached Events.



来源:https://stackoverflow.com/questions/11445028/update-viewmodel-from-view

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