2
votes

I'm new to WPF Prism, my problem is this.

  1. I have a region and I register a view like this

    _container.RegisterType(typeof(Object), typeof(MgpOptions),typeof(MgpOptions).FullName);
    
    _container.RegisterType(typeof(Object), typeof(SgpOptions), typeof(SgpOptions).FullName);
    
  2. Then I navigate to it like this

    _regionManager.Regions[RegionNames.AppBarRegion].NavigationService.RequestNavigate(typeof(MgpOptions).FullName);`
    
  3. On sum button click event I navigate to SgOptions View like this

    _regionManager.Regions[RegionNames.AppBarRegion].RequestNavigate(typeof(SgpOptions).FullName);
    

My problem is when the 3rd step completed both views appear in the region I just want to show one View at a time.

1
i think your view or view model needs to implement IRegionMemberLifetime and implement KeepAlive in order to remove from region when navigating.eran otzap

1 Answers

2
votes

Consider the following as Prism's Regions work differently depending on the control they are being adapted to:

  • If you are using an ItemsControl, you have an AllActiveRegion region type, which basically is a region that never deactivates its views, and therefore, all its views will be considered active. In such scenario, navigating to another view will not deactivate the previous one.

Instead, you need to configure the region as SingleActiveRegion by using ContentControl. This type of region allows only one view to be active at the same time. So when navigating the previous view will indeed get deactivated.

You can find more information related here at Prism Region Overview section.