0
votes

I have a a PopUp with a Region that contains another Region. This popup is invoked through the WPF Prism(MEF) InteractionRequest methodology. The structure looks like so:

PopUpUserControl
  - ContentControl : Region(UserCatalogsCreateRegion)
     - PopUpStageUserControl
       - StackPanel 
          -ContentControl : Region(UserCatalogsCreateStackRegion) <--Disappearing Region

The problem manifests itself like this. When the application starts up and is running normally, I can list the Regions in the application and I can see that the RegionManager contains the Region named "UserCatalogsCreateStackRegion".

Now when I click the button that sets off the InteractionRequest for PopUpCreation, I can see that the list of Regions no longer contains "UserCatalogsCreateStackRegion". I verified that something is removing my Region because I added a CollectionListener to the Regions property of the RegionManager, and as soon as the Popup is created, my breakpoint is hit and the Notif..Action is "Remove" and the OldItem is the Region in question.

TL;DR Region disappears from RegionManager.Regions when the popup that contains said Region is created and invoked.

Any help is greatly appreciated. And I will try to answer as many other questions as possible as there is A LOT that can go wrong with a Region manager.

EDIT

Brian Lagunas' links pointed right to the doggone solution. This was the solution. My final working code for the PopUpStageControl looks like this, where ContentControl is the Region that kept "disappearing":

    [ImportingConstructor]
    public PopUpStageUserControl(IRegionManager regionManager)
    {
        InitializeComponent();
        this.regionManager = regionManager;

        //Fix Begin
        RegionManager.SetRegionName(ContentControl, AppRegions.UserCatalogsCreateStackRegion);
        RegionManager.SetRegionManager(ContentControl, regionManager);
        //Fix End

        RegionManager.SetRegionManager(this, regionManager);
        RegionManager.UpdateRegions();
    }
3
Just an assumption, but when the region is used, it probably gets removed from RegionManager so that it isn't used/shown in another control. When the Popup containing the region is closed/GC'd, I'd imagine it gets added back into the RegionManager. Disclaimer: I've never used PRISM. - Kcvin

3 Answers

2
votes

This is because a popup is not part of the visual tree, so the region manager will not be able to find the region. You will have to manually register the region. See these posts:

Region not loaded by the RegionManger

How to register regions inside user controls or control templates in RegionManager?

PRISM 6 Regions in WPF using DataTemplate/CustomControl

https://github.com/PrismLibrary/Prism/issues/251

0
votes

Going off of my comment and then a quick Google result (old version of PRISM).

The IRegionMemberLifetime interface: Note also that the ModuleARibbonTab class implements the IRegionMemberLifetime interface. This interface is provided by Prism, and it controls whether a View is removed from a region when the user navigates away from the View.

By the sounds of it you might want to implement IRegionMemberLifetime and set KeepAlive appropriately--that might have an effect on when the RegionManager removes/persists the region.

0
votes

Although you do not stated it in your posted code, I assume that you are using something like this when setting up InteractionRequest:

<prism:PopupWindowAction.WindowContent>
    <inf:PopUpStageUserControl/>
</prism:PopupWindowAction.WindowContent>

So you have to be aware that at runtime Prism will replace all popup content with the one you specified in PopupWindowAction.WindowContent.