Prism 4 + MEF + IDialogService - state changes ignored when dialog re-opened

Topics: Prism v4 - WPF 4
Dec 11, 2011 at 9:47 PM
Edited Dec 11, 2011 at 9:49 PM

I try to make Modal Window. I use the approach described in this article, but unfortunately, I have a problem. When I first called Modal Window everything is working correctly.

But if you close the window and open it again Modal Window will not be react to state changes.

I can not understand how to fix it.

Source code

Dec 12, 2011 at 8:52 PM


In my opinion, the recommended approach to create dialog or modal window in Prism is using the WindowDialogActivationBehavior provided in the Stock Trader RI (or the PopupDialogActivationBehavior for Silverlight). Those behaviors will allow you to define a region that, when a view is added to it, will be shown in a new window/popup.

You might find the following threads useful where similar concerns are discussed:

As a possible workaround using your approach, you could add the following code in the code-behind of the Window1 window to handle the Closed event of the window:

private void Window_Closed(object sender, EventArgs e)
    IRegionManager myRegionManager = RegionManager.GetRegionManager(MainRegion);
    IRegion myRegion = myRegionManager.Regions["MainRegion"];

    while( myRegion.Views.Count() > 0)


Like this, we remove all the views from the region and remove the region itself from the RegionManager, so that the next time the Window1 window is created it should work like the first time. Note that in the previous code snippet, we get the RegionManager of the element MainRegion. This element is the ContentControl that acts as the region and has the name "MainRegion."

I hope you find it useful,

Damian Cherubini