我正在使用prism 4框架开发WPF桌面应用程序。在我的应用程序中,我显示了员工列表,当从列表中选择一个员工时,所选员工的详细信息将显示在详细信息区域中。在我的控制器旁边响应员工选择的事件我有以下代码注入EmployeeDetailsVeiw。
IRegion employeeDetailsVeiwRegion = this.regionManager.Regions["EmployeeDetailsVeiwRegion"];
EmployeeDetailsView view = employeeDetailsVeiwRegion.GetView("EmployeeDetailsVeiw") as EmployeeDetailsView;
if(view == null)
{
view = this.container.Resolve<EmployeeDetailsView>();
employeeDetailsVeiwRegion.Add(view, "EmployeeDetailsVeiw");
}
我已将区域定义为
<ContentControl Name="EmployeeDetailsVeiwRegion" Margin="16" Grid.Row="1"
prism:RegionManager.RegionName="EmployeeDetailsVeiwRegion"/>
但是当我运行代码时,我不断收到错误
The region manager does not contain the EmployeeDetailsVeiwRegion region
我已尝试过其他堆叠中提出的解决方案,例如此处a link和其他帖子,但它不适用于我。
答案 0 :(得分:2)
终于开始工作了。我在ContentControl上设置了区域管理器,其中包含我的演示者类(在我的例子中是EmployeePage)承包商中的区域。
IRegionManager regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
regionManager.Regions.Remove("EmployeeDetailsViewRegion");
RegionManager.SetRegionManager(this.EmployeeDetailsContentControl, regionManager);
答案 1 :(得分:0)
尝试:
this.regionManager.RegisterViewWithRegion("EmployeeDetailsVeiwRegion",
typeof(EmployeeDetailsView));