Closing popup without using X button?

Topics: Prism v4 - WPF 4
May 25, 2011 at 4:48 PM

I wanted to add a file menu to the news reader popup so that the user could close the window a different way.

What code do I need to put in my view model so that the DialogActivationBehavior will fire just like when the X button is pressed?

May 26, 2011 at 3:00 PM
Edited May 26, 2011 at 4:21 PM


You could try removing the view from the popup region you have created. That would cause the popup to be closed.

For example, if you are using navigation, and you have registered your view in the DI container you're using with a contract named "SomeView", your code would look like this:




Or if you have your view registered in the container with its type as the contract, your code could look like this:




Assuming this.regionManager is an instance of the region manager, and the view is registered as a singleton instance.

I hope you find this helpful.

Guido Leandro Maliandi

May 26, 2011 at 6:01 PM


For some reason I was having issues with the ServiceLocator not finding the view so I made a method in my controller that can remove the views.

public void RemoveView(string regionName, string viewName)
    // Check to see if the region exists.
    if (this.regionManager.Regions.ContainsRegionWithName(regionName))
        IRegion region = this.regionManager.Regions[regionName];

        object currentView = region.GetView(viewName);

        // If the view exists in the region remove it.
        if (currentView != null)