azmuhak
azmuhak

Reputation: 974

initializing View from a different ViewModel in MVVM

I am working on a WPF map application and I a View and a ViewModel in my MVVM WPF App. The user clicks on the button in the View (lets call it View#1) and then the ViewModel adds the map to the window. However there is another View (lets call that View#2) in my App which is responsible for the map manipulation. I cannot add the controls used in View#2 to View#1 because View#1 is just a listbox with different map names.

I want View#2 to get initialized and shown on the screen from the ViewModel#1.

Is this approach against good MVVM programming practice to initialize a View from a different ViewModel? If yes then what is the correct way of dealing with these situations.

Thanks

Upvotes: 0

Views: 225

Answers (1)

Nickolai Nielsen
Nickolai Nielsen

Reputation: 942

Normally you inject you viewmodel into your view, so you can only have one view on one view model.

But you could have a View#0 that contains both View#1 and View#2. The ViewModel#0 would have 2 properties containing ViewModel#1 and ViewModel#2

Upvotes: 1

Related Questions