Sharing state/changes across ViewModels
Posted
by joshperry
on Stack Overflow
See other posts from Stack Overflow
or by joshperry
Published on 2010-06-10T20:39:06Z
Indexed on
2010/06/10
20:42 UTC
Read the original article
Hit count: 208
I have an App which has a Tasks tab and a Projects tab. I decided to make a separate ViewModel for each of the tabs, TasksViewModel and ProjectsViewModel.
The Tasks tab has a new task area with an associated project pulldown and the Projects tab (obviously) has a list of projects.
What I'd like is for the pulldown on the Tasks tab to share the same collection as the Projects tab list so that any time I add or remove a project on the Projects tab the list on the Tasks tab is up to date automatically. This worked well with a single ViewModel but it was beginning to become quite unruly.
Should I not have split into two ViewModels? Is there a common method of sharing data like this? Perhaps pass the same ObservableCollection<Project>
into each of the ViewModels? Perhaps some type of notification back to the TasksViewModel along the lines of ICollectionChanged
.
Appreciate any insight/input!
© Stack Overflow or respective owner