【问题标题】:WPF, Prism 7.2, Dragablz, View with Prism Region loaded but ViewModel constructor injected region manager contains no regionsWPF,Prism 7.2,Dragablz,加载了 Prism 区域的视图,但 ViewModel 构造函数注入的区域管理器不包含任何区域
【发布时间】:2020-05-22 16:32:18
【问题描述】:

简单视图是 Dragablz Tab 的子视图,定义如下:

UserControl x:Class="Esc.Eris.Apps.Dashboards.Views.DashboardViewer"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         mc:Ignorable="d" 
         d:DesignHeight="450" d:DesignWidth="800"
         xmlns:prism="http://prismlibrary.com/"
         prism:ViewModelLocator.AutoWireViewModel="True">
        <Grid>
            <ContentControl prism:RegionManager.RegionName="DashboardViewerContentRegion" />
        </Grid>
</UserControl>

通过在 ViewModel 构造函数中设置断点,我可以检查 IRegionManager regionManager 注入参数的内容,但 regionManager 不包含任何区域。

我以为视图中的 prism:RegionManager.RegionName= 声明自动向 regionManager 注册了区域,但显然不是。

这不是我的第一个 Prism 应用,但这是我第一次看到这种行为。

包含此视图的模块已通过 App.xaml.cs 文件中的 ConfigureModuleCatalog 添加到 moduleCatalog。

有人能解释一下这里发生了什么吗?

提前致谢!

【问题讨论】:

    标签: c# wpf prism


    【解决方案1】:

    在做了很多 SO 研究之后,我在 View 构造函数中添加了一个 RegionManager.SetRegionManager 调用。如果没有 SetRegionManager 函数调用,则不会将任何区域添加到 regionManager.Regions 集合中。我还在视图 xaml 中为视图“已加载”事件添加了事件交互触发器声明。此触发器在视图模型中调用 ViewLoaded 命令,该命令会触发一个 5 秒时间受限的任务,该任务会检查 regionManager Regions 集合中是否有来自视图的任何已注册区域。有趣的是,视图区域出现在视图模型的 regionManager.Regions 集合中需要将近 30 毫秒,然后我可以通过 RequestNavigate 函数调用填充该区域。

    通常使用 Prism,我不需要做任何这些。

    视图是 Dragablz Tab 的子视图,我只能猜测是 Dragablz 环境要求我跳过额外的箍来注册视图区域 .... 但这纯粹是我的猜想部分。

    【讨论】:

      猜你喜欢
      • 2012-07-25
      • 2013-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多