创建 Popup 时 PRISM 区域消失

PRISM Region Disappears when Popup is Created

我有一个弹出窗口,其中一个区域包含另一个区域。此弹出窗口通过 WPF Prism(MEF) InteractionRequest 方法调用。结构如下所示:

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

问题是这样表现的。当应用程序启动并正常 运行 时,我可以列出应用程序中的区域,我可以看到 RegionManager 包含名为 "UserCatalogsCreateStackRegion".

的区域

现在,当我单击为 PopUpCreation 触发 InteractionRequest 的按钮时,我可以看到区域列表不再包含 "UserCatalogsCreateStackRegion"。我验证了某些东西正在删除我的区域,因为我向 RegionManager 的区域 属性 添加了一个 CollectionListener,并且一旦创建了 Popup,我的断点就命中了并且 Notif..Action 是 "Remove" OldItem 是有问题的区域。

TL;DR 区域在创建并调用包含所述区域的弹出窗口时从 RegionManager.Regions 中消失。

非常感谢任何帮助。我会尽可能多地回答其他问题,因为区域经理可能会出错。

编辑

Brian Lagunas 的链接指向了 doggone 解决方案。这就是解决方案。 PopUpStageControl 的最终工作代码如下所示,其中 ContentControl 是保持 "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();
    }

结束我的评论,然后快速 Google result(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.

听起来你可能想要实施 IRegionMemberLifetime 并适当地设置 KeepAlive——这可能会影响 RegionManager removes/persists 区域.

虽然您没有在发布的代码中说明,但我假设您在设置 InteractionRequest 时使用的是这样的东西:

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

因此您必须注意,在运行时 Prism 会将所有弹出内容替换为您在 PopupWindowAction.WindowContent 中指定的内容。

这是因为弹出窗口不是可视化树的一部分,因此区域管理器将无法找到该区域。您将必须手动注册该区域。查看这些帖子:

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