Reputation: 416
I have two view models ViewModelA
and ViewModelB
they both use a common DataServiceA
to retrieve a User Setting called Theme
. ViewModel
B can change that setting and save it to the database. When this occurs the ViewModelA
does not update that theme value.
I have been trying to figure out the proper course of action to allow it to update it as well and have come up with a few options:
Any ideas?
Upvotes: 0
Views: 1035
Reputation: 2931
Sounds like a good case for using events, if they both have access to DataServiceA could you not raise an event when the theme is changed?
So.. in the DataServiceA, "OnThemeChanged" event is raised when the theme is modified and the ViewModels can subscribe to the event and update their content when it is raised.
Upvotes: 1
Reputation: 17395
If both of them use the same instance of DataServiceA
, I don't think it's such a bad idea that DataServiceA
will also implement INotifyPropertyChanged and raise an event when the Theme
property changes.
But if you don't like that idea, another option is to use the EventAggregator and publish the event. I personally think the first option is quite sufficient but it's your call...
Upvotes: 0