简单的视图是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添加到模块目录中的。
谁能解释一下这里发生了什么?
先谢谢你
在做了大量的SO研究后,我在View构造函数中添加了一个RegionManager.SetRegionManager调用。如果没有SetRegionManager函数调用,任何区域都不会被添加到regionManager.Regions集合中。 我还在视图xaml中为视图 "Loaded "事件添加了一个事件交互触发声明。这个触发器在视图模型中调用了一个ViewLoaded命令,这个命令会启动一个5秒的时间限制任务,检查regionManager Regions集合中是否有来自视图的任何注册区域。 有趣的是,视图区域出现在视图模型中的regionManager.Regions集合中需要将近30ms的时间,然后在这时,我可以通过RequestNavigate函数调用来填充该区域。
通常使用Prism,我从来不需要做这些事情。
视图是Dragablz Tab的子代,我只能猜测是Dragablz环境要求我跳过额外的圈圈来注册视图区域......但这纯属我的猜测。