Instantiate / call other views (WPF forms) with your ViewModels using MVVM and Unity

I am using MVVM and Unity, I understand how to show the wrapper of the View (MainView with MainViewModel), but I could not find the correct way to instantiate other windows, for example: Details button that opens new forms and show other details.

So, I'm looking for a general way to create / call other views (WPF windows) with my ViewModels using MVVM and Unity.

+3


source to share


2 answers


This answer might help with understanding how to link multiple views / viewModels together. I usually don't need to open additional windows, just displaying different views in the current window.



Please let us know if you are looking for an MVVM solution for opening new windows.

+2


source


Take a look at this answer: Handling User Interaction in MVVM . You can use the interop service to create new WPF windows that will still remain unbound.

You can also provide indirect communication in WPF by using the Mediator template to post a message from the view model that causes a new view to be created. This answer Simple mediation implementation gives a quick overview.



I recommend that you read the User Interaction Patterns guide as it covers many of the scenarios you will come across when using MVVM.

+2


source







All Articles