简体   繁体   中英

Prism Error : The region manager does not contain the region

I am developing a WPF desktop application using prism 4 framework. In my application i show a list employees and when one is is selected from the the list the details of the selected employee is shown in details region. in side my controller for responding to employee selected event i have the following code for injectiong the 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");
    }

I have define the region as

    <ContentControl Name="EmployeeDetailsVeiwRegion" Margin="16" Grid.Row="1"
              prism:RegionManager.RegionName="EmployeeDetailsVeiwRegion"/>

But when i run the code i keep getting the error

  The region manager does not contain the EmployeeDetailsVeiwRegion region

Attempted Solution

I have tried out the solution proposed in other stack over plow posts such as here a link and other posts, but it is not working for me.

Finally got it to work. I set the region manager on the ContentControl that contains the region in my presenter class (in my case EmployeePage) contractor.

IRegionManager regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
regionManager.Regions.Remove("EmployeeDetailsViewRegion");
RegionManager.SetRegionManager(this.EmployeeDetailsContentControl, regionManager);

Try:

this.regionManager.RegisterViewWithRegion("EmployeeDetailsVeiwRegion",
    typeof(EmployeeDetailsView));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM