I don't have the code currently available, so I'll try to be as descriptive as possible.
I have a shell window with a menu. The menu has a menu item that opens a new modal dialog window with the shell window as it's parent. I'm opening the dialog window using a custom interaction request and trigger action. The Content property of the custom INotification event takes a view (which is a window control in this case), and the view itself takes an IRegionManager as it's constructor.
[Import]
public IRegionManager { get; set; }
...{ Content = new DialogWindowView(regionManager.CreateRegionManager()) }
Then when the Action is called from the Shell view it gets a reference to the window from the Content property and calls content.ShowDialog()
Then in the dialog window's constructor I'm adding some views to the dialog window's regions.
public IRegionManager RegionManager { get; set; }
public DialogWindowView(IRegionManager regionManager)
{
this.RegionManager = regionManager;
RegionManager.RegisterViewWithRegion("region1", typeof(view1));
RegionManager.RegisterViewWithRegion("region2", typeof(view2));
RegionManager.RegisterViewWithRegion("region3", typeof(view3));
}
In the dialog window's view I'm binding the regions to dialog window's region manager, like so:
<ContentControl
prism:RegionManager.RegionManager="{Binding RegionManager, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"
prism:RegionManager.RegionName="region1"/>
The dialog window loads and displays the views in it's regions, but when I close the dialog window and try to open it again it fails saying it can't add the views to the regions because they already exist. I'm not sure how that's even possible since every time I open a dialog I'm calling new
on the dialog (so it should be a new dialog) and I'm passing in a brand new region manager (which should have no views associated with it). I've tried manually removing the views on the windows Closing event, and it appears to remove them, but then the dialog still won't reopen with an error that it cannot create the views.
How do I properly open a new dialog window with it's own scoped region manager so that I can close it and reopen it?
I changed from view discovery to view injection and moved the code that adds the views to the region from the constructor to the loaded event.
RegionManager.Regions["region"].Add(ServiceLocator.Current.GetInstance<view>());
Without doing some more research I'm not 100% sure the difference between the two approaches, but it's working now, so that makes me happy.