Answer the question
In order to leave comments, you need to log in
How to create a new window from a ViewModel within the MVVM pattern?
Hello. I need to call a view from another module's viewmodel. That is, I have a ProcurementManager module, it has a viewmodel, from which a view should be called, which is located in another module, the Ticket module. How can this be done without breaking the pattern?
Answer the question
In order to leave comments, you need to log in
In a good way, you should create a DialogService that will have a Show(BaseViewModelType viewModel) method and inject this service in the right places. IoC (DI container, to be more specific) will help you here.
There are, of course, other ways. Events, for example. Your ViewModel should have an event (Action) that the main window will subscribe to, for example, and react accordingly.
Views for a specific ViewModel in both cases can be described as a DataTemplate and bind the displayed ViewModel to the ContentPresenter, which itself will find the appropriate Template by the ViewModel type
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question