Modal Dialog Boxes

Topics: Prism v4 - WPF 4
Apr 18, 2011 at 5:34 PM


I am fairly new to Prism and WPF so please bear with me.

I want to create a modal dialog box in my application (for the moment - a simple About Box).

Looking at the docs and the sample StockTrader RI application, it seems that the approach I should take is as follows:
01) Create a standard MVVM module which contains the AboutBoxView (user control), AboutBoxViewModel class, and AboutBoxModel class
02) Register these with Prism / the container like I do with any other module. However, the view won't be registered in a region
03) Create a CompositePresentationEvent which will be used to tell the application that I want to display the about box
e.g. public class AboutBoxRequestedEvent : CompositePresentationEvent<string> {}
04) On my toolbar or menuitem's viewmodel, I can publish the event in the ExecuteAboutBoxMenuItemCommand
e.g. EventAggregator.GetEvent<AboutBoxRequestedEvent>().Publish(null);
05) Not too sure where I should put the event Subscribe code. I was thinking of putting it into the main Shell viewmodel class. Is this what people normally do, please let me know. Perhaps there is a better place for it.
06) The code to actually display the AboutBoxView will leverage the classes contained in the Infrastructure\Behaviours classes contained in the StockTraderRI sample.

Just wanted to get other peoples opinion on this approach before I start.




Apr 18, 2011 at 7:13 PM

Hi Liam,

The approach you’re mentioning is a valid possibility to fulfill a set of use cases in Prism grouped into a module.

You should take into account the following:

03) The composite presentation event should be placed in an infrastructure project, since the event needs to be able to be referenced from within other modules that wish to publish or subscribe to that event, without having to reference your module.

05) You should subscribe to that event from within your module, since that module is responsible for fulfilling the use case of displaying an about box.

Take into account that if your use case is as simple as displaying an about box, the overhead of using the EventAggregator and placing the code in a separate module might not be worth the benefits of isolating it, hence you could place that behavior in your shell project or in another module if appropriate.

You can read more about this topics in the following links:


Miguel Bronzovic