0

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.

Community
  • 1
  • 1
meha0250
  • 203
  • 2
  • 10
  • Can you check your spelling of EmployeeDetailsVeiwRegion in all places? You have `View` spelt `Veiw`. A simple typo (even the wrong case) will cause it to fail. – iCollect.it Ltd Jun 11 '12 at 11:19
  • I have had that error in the past. What caused it for me was that I had a different instance of the region manager in different parts of my code. – Gus Jun 11 '12 at 12:11
  • @HiTech Magic yes i have checked for typo mistakes they were not the problem – meha0250 Jun 11 '12 at 12:59
  • @Gus How did make the region manager the same instance indifferent parts of your code – meha0250 Jun 11 '12 at 13:00
  • Are you using unity to ensure that you've only created one instance of the RegionManager? Also, you should verify that the view has been created before you get the region since the RegionManager won't know of that region. From your code it looks like you tried to get the region first before creating the view. – Hoang Dang Jun 11 '12 at 14:54
  • @HoangDang How do i ensure that only one instance of RegionManager get created? (i am new to this) – meha0250 Jun 11 '12 at 21:38
  • @meha0250 -- there are a million ways to do it -- but in Unity using code it looks something like myContainer.RegisterInstance(new RegionManager()); then make sure that you are constructor injection to inject the region manager into your controller (and registering your controller in the same unity container). – Gus Jun 12 '12 at 17:13
  • @Gus i didnt get what you menat by "make sure that you are constructor injection to inject the region manager into your controlle" – meha0250 Jun 13 '12 at 13:35
  • I tried everything, but the first time I try to navigate to another view using the injected region manager, it doesn't work. I checked, and the RegionCollection is always empty at this point. – Fabricio Dec 15 '17 at 14:00

2 Answers2

3

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);
meha0250
  • 203
  • 2
  • 10
-1

Try:

this.regionManager.RegisterViewWithRegion("EmployeeDetailsVeiwRegion",
    typeof(EmployeeDetailsView));
Hoang Dang
  • 298
  • 2
  • 9