3

I'm using MVVM and Unity, I've understrood how to show the shell View (MainView with its MainViewModel) but I couldn't find the right way to instantiate other windows, for example : Details Button that opens a new form and show other details.

So, I'm looking for a common way how to instantiate/Call other Views(WPF windows) with their ViewModels using MVVM and Unity.

HichemSeeSharp
  • 3,240
  • 2
  • 22
  • 44

2 Answers2

2

Take a look at this answer: Handling user interactions in MVVM. You can utilize an interaction service to instantiate new WPF windows will still remaining decoupled.

You can also provide indirect communication in WPF by leveraging the Mediator pattern to publish a message from a view model that causes a new view to be instantiated. This answer Simple Mediator implementation gives a quick overview.

I recommend you read over the User Interaction Patterns guidance, as it covers many of the scenarios you will face when using MVVM.

Community
  • 1
  • 1
Oppositional
  • 11,141
  • 6
  • 50
  • 63
2

This answer may help with understanding how to link multiple views/viewModels together. I don't typically find myself needing to open additional windows just displaying different views in the current window.

Please let us know if you're looking specifically for an MVVM solution for opening new windows.

Community
  • 1
  • 1
Erick
  • 486
  • 2
  • 12
  • Actually, I want to put MVVM and Unity together so that I can call and remove views from a window and, if necessarily, call new windows (View/ViewModel), ex : windows1 shows users list and once I click on Details button I get another window showing me its details so I can read or edit etc. That's it ! thanks – HichemSeeSharp Apr 05 '12 at 11:24
  • 1
    Working with MVVM can be a pain I highly recomend using a framework to assist and most of the frameworks have examples on how to do just what you're looking for. http://stackoverflow.com/questions/1409553/what-framework-for-mvvm-should-i-use is an excellent question and answer for mvvm frameworks – Erick Apr 05 '12 at 19:01
  • Thanks a lot Erick, I will download all of these frameworks and find out which one would fit my needs. – HichemSeeSharp Apr 05 '12 at 20:36