Synchronizing ViewModels in WPF
simple problem (using WPF/C#, MVVM, Entity Framework):
I have two non-modal dialog windows. Both windows use the same entities. But two different ViewModels
because the ViewModels are created in both constructors of windows and so 开发者_StackOverflow中文版two different ObjectContexts
.
Question: Two ViewModels
use two different ObjectContexts
(of EF) but I need to have both windows synchronized. That is, when user changes some entities in one window, the second one should be notified. Entities are shown as lists with details.
Please, what's the most principal way how to do that in MVVM?
I think you need to take a step back here. It seems to me that what you really want is to share a single ViewModel across two different windows, so why don't you just do that? Move out the responsibility of the creation of your ViewModel out of the ctors of those two windows and put it in something that will be responsible to instantiate your windows with a shared ViewModel instance.
精彩评论