Update ViewModel from View

2019-08-26 10:16发布

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?

3条回答
虎瘦雄心在
2楼-- · 2019-08-26 10:53

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

查看更多
放荡不羁爱自由
3楼-- · 2019-08-26 10:55

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

查看更多
乱世女痞
4楼-- · 2019-08-26 11:11

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

查看更多
登录 后发表回答