Children's windows in MVVM

I have problems understanding MVVM. My application relies on dialogs for certain things. The question is, where should these child windows come from? According to MVVM, viewmodels should contain only business logic and have zero actual knowledge of the user interface. However, what other place should I call my child windows, considering them interface elements?

Does this create a tight connection between the elements?

+3
source share
6 answers

Since you marked the question with Prism, I suggest how I did it in the past using Prism. Paste IEventAggregator into your ViewModel, and then when you want to open the dialog, post "ShowDialogEvent" or something like that. Then add another module called "DialogModule" or something else that, after initialization, subscribes to this event and displays a dialog. Also, if you want to transfer the data back to the original ViewModel, suggest the ViewModel of the dialog box to publish “DialogCloseEvent” or something similar with a payload of the data you need. You can then subscribe to this event in your main ViewModel.

+1
source

, Unity , Show() . ViewModel IScreen screen = container.Resolve<IScreen>(Resources.EditorWindowKey);, screen.Show();.

, Unity, , .

0

, , - "". , ViewModel, . ChildWindow, , , . , , , ViewModel , .

(, - ) . , , , .

0
0

, , DI'ed dialogController, . (.. ) dialogController.ShowDialog(<<ViewNameToHostInRegion>>,<<RegionName>>).

MessageBus. , ShowDialog(), Messagebus (, Dialog), - "" - / Messagebus. , .

:

1) BlackBox. .. , Dialog.

2) -

3) , \.

-, , Dialog, . TestableDialogController, ShowDialog ( IDialogController ShowDialog().

psudeo:

LocalMessageBus.AddMessage(<MessageKey>,<MessageActualContentAsObject>);
dialogController.ShowDialog(<TargetViewName_SayEmployeeList>);
Employee selectedEmployee = LocalMessageBus.GetMessage(<MessageKey>) as Employee;
if (selectedEmployee != null)
{
//doSomework with selected employee
}
0

Source: https://habr.com/ru/post/1750474/


All Articles