Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - MVVM - View model hierarchy

Tags:

mvvm

wpf

Can somone give me an example why would I need a ViewModel taht contains two sub View models ? and how do I implement this ?

like image 886
Erez Avatar asked Oct 15 '22 03:10

Erez


1 Answers

Assuming you got a "MainContainer" which is your top-level ViewModel, you might need 2 different sub-viewmodels: One for a "Menu" and one for the content that the menu points to.

It could be implemented like this:

public MenuViewModel Menu;
public ContentViewModel Content;

You'd bind a container in your main view to each of these viewmodels, and on update insert a view depending on your viewmodel. How you map the viewmodels to the view, can depend, and there's no "pretty" solution. Personally, I like to keep it in my top-view resources, using a datatemplate.

like image 76
cwap Avatar answered Oct 19 '22 03:10

cwap