Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVVM multiple views

Tags:

mvvm

wpf

Im trying to learn MVVM so far its going well , I have stumble on a situation which I don't know how to implement ..

What I want : - A view with left navigation and right details pane .. right details will have a contentcontainer which would hold my User Controls for the views to be selected by left pane

What I have : - A MainViewModel - ViewModels for Each of the Entities I have on my database

My Problem : - Since I will have an ObservableCollection of my VIEWMODELS in my MAINVIEWMODEL ( as per the example i'm patterning my application ) do I create a public property for each of my MODEL Entities which will be used for the databinding I have defined in my UserControls ??

like image 362
Dennis Avatar asked Dec 02 '25 21:12

Dennis


2 Answers

You can create a Base Type for all of your ViewModels to be displayed on the right side.(lets call that as BaseContentViewModel) Then your left side ListBox will be bind to ObservableCollection<BaseContentViewModel> and the SelectedValue of the ListBox will bind to a new MainViewModel.SelectedContent proeprty of Type BaseContentViewModel.

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

Now it is just a matter of defining different UserControls as DataTemplates in the Resource XAMLs (Usually refers as ViewToViewModelMapping in MVVM)

like image 183
Jobi Joy Avatar answered Dec 05 '25 14:12

Jobi Joy


Have a look at John Papa's PDC talk 'Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight'. In it he illustrates an approach for managing an application that has multiple MVVM triads.

like image 42
Rus Avatar answered Dec 05 '25 13:12

Rus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!