Multiple MVVM views

I am trying to learn MVVM, while it is going well, I came across a situation that I do not know how to implement.

What I want: - View from the left navigation bar and the right information. The right side will contain a content container that will contain my user controls for the views that will be selected by the left panel

What I have: - MainViewModel - ViewModels for each of the objects that I have in my database

My problem: - Since I will have an ObservableCollection of my VIEWMODELS in my MAINVIEWMODEL (as in the example, I draw my application), I create a public property for each of my MODEL objects that will be used to bind the data that I defined in my UserControls? ?

+3
source share
2 answers

You can create a base type for all of your ViewModels, which will be displayed on the right side. (Lets call it like BaseContentViewModel) Then your left side of the ListBox will be bound to ObservableCollection<BaseContentViewModel>, and the SelectedValue from the ListBox will be bound to the new MainViewModel.SelectedContent function of type BaseContentViewModel.

And on the right side you need to have a ContentControl to which the SelectedContent binds to ContentControl.Content

Now it's just a matter of defining different UserControls as DataTemplates in XAML resources (usually this means ViewToViewModelMapping in MVVM)

+5
source

PDC " Microsoft Silverlight". MVVM.

+2

Source: https://habr.com/ru/post/1731866/


All Articles