How to notify all properties of the view model has changed

回眸只為那壹抹淺笑 提交于 2019-12-03 01:13:16

Just raise the PropertyChanged event with an empty string as the property name :

OnPropertyChanged(String.Empty);

Ok what I understood from your question is this..

View <> ViewModel <> Entity (with a bunch of properties)

View is bound to ViewModel, which delegates to Entity. You now want to replace the backing entity and signal the view to refresh to update to the newer entity.

I'd suggest implementing an indexer in the ViewModel which takes in a string (the name of the backing property). The ViewModel can be used as a cache if required, delegating to the backing entity only on a miss.

When you replace the entity, the viewModel clears its cache and fires NotifyPropertyChanged (in the indexer set) with String.Empty or null. Which I learned today, indicates all properties have changed.

This way you don't create n delegating properties in the ViewModel. A google search result shows that it has been tried at least once with success.

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