S
S
slav4ik514932016-11-04 21:17:03
WPF
slav4ik51493, 2016-11-04 21:17:03

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

1 answer(s)
D
Donil, 2016-11-10
@Donil

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 question

Ask a Question

731 491 924 answers to any question