3

I have a StockModule and a PurchaseModule. When I receive a new purchase, I add that to the Stock Model in the database.

My problem is that I have an ObservableCollection stockList in the ViewModel in my StockModule and the controller that adds the stock is in the PurchaseModule. I don't know how I'm supposed to tell the ViewVodel in the StockModule that I have updated the stockList already.

I am using databinding in wpf and prism with unity. Updating the view within a module is easy enough but I haven't found a way to do it between two modules.

Should I pass a reference to the StockController when I initialize my PurchaseModule? I don't want to do that because that seems too tightly coupled.

4

1 回答 1

3

您应该使用 MarlonMediatorEventAggregatorPrism 之类的东西来实现 ViewModel 或组件之间的通信(它们可以在单个模块中,也可以跨多个模块)。

在您的情况下,您的 ViewModelPurchaseModule将通过 Mediator/EventAggregator 发布一条消息(例如,StockAdded),然后您的 ViewModelStockModule将侦听此消息并更新其数据并生效视图。

更多关于调解员的阅读:http: //marlongrech.wordpress.com/2009/04/16/mediator-v2-for-mvvm-wpf-and-silverlight-applications/

棱镜事件聚合器:http: //msdn.microsoft.com/en-us/library/ff921122.aspx

于 2013-10-27T14:12:40.430 回答