0

My application has a menu, content area, and status bar. The user can select File -> Database which prompts the user for database parameters (server and port) in a new window. When the user clicks the “ok” button we need to update the status bar with the new connection.

I know the menu item view should be bound to a command that is in the view model but how should I go about displaying the window? Creating it in the view model seems wrong. Publishing an event on the event aggregator seems to be giving up to much control.

Updating the status bar using the event aggregator makes a lot of sense to me because many different parts of the application could care that the database changed.

Note: I'm using Prism

justin15
  • 63
  • 7
  • You would think should be trivial to do, after all dialog windows have been around since the beginning of the GUI. But no, this is not trivial with WPF and MVVM... Long story short, to maintain the MVVM 'purity' the ViewModel can't know of such 'dirty' things as dialogs (gasp! UI concerns!). So instead you have to create a Dialog Service which the viewmodel is given a reference to (though DI) and the viewmodel uses the service to say 'I need a dialog to be displayed'. See http://stackoverflow.com/questions/21301981/the-pretty-way-to-make-a-modal-dialog-in-wpf-with-prism-and-mvvm-pattern – user469104 Nov 16 '15 at 18:33

1 Answers1

0

If you are using Prism (which I believe you are sinc eyou used the Prism tag) and just need to capture simple values then you can use the PopupWindowAction.

https://github.com/PrismLibrary/Prism/blob/master/Documentation/WPF/45-AdvancedMVVMScenarios.md#using-interaction-request-objects

Otherwise a dialog service would also work.

  • What do you think of using the event aggregator instead of creating a separate dialog service? If we have to many events that could become unmaintainable so we could maybe do some filtering. Another idea is to have a application and module specific event aggregators. Some of our dialogs are simple but others are very complex. Thoughts? – justin15 Nov 24 '15 at 00:56
  • No way! The EventAggreagtor is for publishing messages, not showing dialogs. –  Nov 24 '15 at 01:32