Sharing Data between Silverlight ViewModels

主宰稳场 提交于 2019-12-12 01:28:57

问题


I have a complex User Control that contains some views, each have its own ViewModel. My question is how can all of these ViewModels share some data (for example an observable collection) without each one have a separate call to the service?


回答1:


The service should be an abstraction of the data. Whether that data is pulled from a WS, DB, etc...should be irrelevant. Each ViewModel can contain a property which will be bound to by the View. That property can be an ObservableCollection<T> which wraps a call to the service. That data may in fact be cached via the service and only update periodically but either way it will push the data to a single point of reference for retrieval amongst the ViewModels.



来源:https://stackoverflow.com/questions/4429708/sharing-data-between-silverlight-viewmodels

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