I lately had the problem of creating add and edit dialogs for my wpf app.
All I want to do in my code was something like this. (I mostly use viewmodel first approach
If you are talking about dialogue windows and not just about the pop-up message boxes, please consider my approach below. The key points are:
Module Controller
into the constructor of each ViewModel
(you can use injection).Module Controller
has public/internal methods for creating dialogue windows (just creating, without returning a result). Hence to open a dialogue window in ViewModel
I write: controller.OpenDialogEntity(bla, bla...)
Pros:
Module Controller
is a simple way to avoid strong references and still allows to use mock-ups for testing.Cons:
where T
is enumeration of entities (or for simplicity it can be type of ViewModel).Module Controller
can be overwhelmed by methods for creating windows. In this case it's better to split it up in several modules.P.S. I have been using this approach for quite a long time now and ready to defend its eligibility in comments and provide some examples if required.