I have a main window with a tab control containing 2 tabItem
s:
I currently have 1 ViewModel
which services Tab1 & Tab2. This ViewModel
is becoming a little bloated with blurred SOC. I want to split the logic into 2 viewmodels: ViewModel 1 & ViewModel2. My understanding is that you can set the Main Window DataContext
to a Base ViewModel which holds a collection of ViewModels & then you can assert each TabItem to a different ViewModel.
The example's I've seen of these base ViewModels expose an ObservableCOllection like so:
private ObservableCollection<ViewModel1> _viewModelCollection
Public Observable Collection<ViewModel1> ViewModelCollection
{
get { return _viewModelCollection; }
set
{
_viewModelCollection = value;
OnPropertyChanged("ViewModelCollection");
}
}
public BaseViewModel()
{
ViewModelCollection = new ObservableCollection<ViewModel1>();
ViewModelCollection.Add(new ViewModel1(Tab1);
ViewModelCollection.Add(new ViewModel1(Tab2);
}
But how do I assign a different ViewModel to each TabItem? I would want Tab1= ViewModel1 & Tab2=ViewModel2?