在现有导航窗口中添加 PRISM 区域管理器

发布于 2024-08-31 16:59:06 字数 1057 浏览 9 评论 0原文

我们有一个基于 NavigationWindow 的“旧版”WPF 应用程序。 NavigationWindow 有一个相当大的 ControlTemplate,其中包含一个 ContentPresenter,如下所示:

<ControlTemplate>
    ....snip...
<ContentPresenter x:Name="PART_NavWinCP" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
    .....snip....
    </ControlTemplate>

我们想要做的是使用该 ContentPresenter 作为第一个选项卡,并在运行时动态添加其他选项卡。像这样:

    <ControlTemplate>
....snip...
<TabControl Background="Transparent" cal:RegionManager.RegionName="MainRegion" Grid.ColumnSpan="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
       <TabItem Header="Nav Window Content">
           <ContentPresenter x:Name="PART_NavWinCP" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
       </TabItem>
    </TabControl>
.....snip....
</ControlTemplate>

然后我们的模块获取 RegionName 并动态插入其内容。问题似乎是 PRISM 区域经理不喜欢我们的代码位于 ContentTemplate 中并且无法解析该区域。我尝试过更新 RegionManager,动态添加区域,只是有一个根选项卡控件,没有 ContentPresenter,但我无法让它工作。有什么想法吗?

We have a "legacy" WPF applicaton that is based on a NavigationWindow. The NavigationWindow has a fairly large ControlTemplate that houses a ContentPresenter as so:

<ControlTemplate>
    ....snip...
<ContentPresenter x:Name="PART_NavWinCP" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
    .....snip....
    </ControlTemplate>

What we want to do is use that ContentPresenter as the first tab and dynamically add other tabs at run time. Like this:

    <ControlTemplate>
....snip...
<TabControl Background="Transparent" cal:RegionManager.RegionName="MainRegion" Grid.ColumnSpan="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
       <TabItem Header="Nav Window Content">
           <ContentPresenter x:Name="PART_NavWinCP" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
       </TabItem>
    </TabControl>
.....snip....
</ControlTemplate>

Then our Modules grab the RegionName and insert their content dynamically. The issue seems to be that the PRISM region manager doesn't like that our code is in a ContentTemplate and cannot resolve the region. I have tried updating the RegionManager, adding the Region dynamically, just having a root tab control without the ContentPresenter, but I cannot get this to work. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我很OK 2024-09-07 16:59:06

模板中的区域是一个问题 - 因为模板是在初始内容之后渲染的,它们不是“控件”,甚至不是实例本身,并且区域管理器无法处理它。我假设不支持以这种方式添加区域。

现在,没有模板的直接选项卡控件我能够很好地工作,但回想起来需要编写一个内容适配器,该适配器知道如何处理目标区域类型并在加载模块之前在引导程序中注册它。

Regions in templates are an issue - since templates are rendered after the initial content they arent 'controls' or even instances per-se and the region manager has no way to get handle on it. i would assume adding a region this way wouldnt be supported.

Now, staright up tab control w/ no templates I was able to get to work just fine but recall needing to write a content adapter that knew how to handle the target region type and registering that in the bootstrapper before i did the module loading.

昇り龍 2024-09-07 16:59:06

因此,我们通过将 NavigationWindow 更改为框架并将内容放入框架中来解决此问题。我们需要做一些造型以使其看起来不错;但是,这是避免在 NavigationWindow 内容模板中使用区域的唯一方法。我们现在从应用程序通用的框架中删除所有代码,并且 Shell 需要这些代码(因为 NavigationWindow 无法成为 Shell)。

So we got around this by chaning the NavigationWindow to a Frame and dropping the content in the frame. We need to do a bit of styling in order to make it look good; however, this is the only way to get around the use of a region in a NavigationWindow content template. We are now removing all code from the frame that was common to the app and will be needed by the Shell (since the NavigationWindow cannot become the Shell).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文