I use in the application of WPF and Prism with UnityContainer. Inside the application, a separate window is launched with the following contents:

<StackPanel Grid.Column="0"> <RadioButton Margin="5" Command="{Binding AutoSchemeCommand}" Content="Auto" /> <RadioButton Margin="5" Command="{Binding SingleSchemeCommand}" Content="Individual" /> <RadioButton Margin="5" Command="{Binding SelectSchemeCommand}" Content="Select from scheme" /> </StackPanel> <ContentControl Grid.Column="1" Margin="10,0" regions:RegionManager.RegionName="TypeSchemeRegion" /> 

That is, the window contains the region in which the content will change by pressing the corresponding RadioButton. To do this, there are appropriate subwindows and in the start module they are initialized:

  RegionManager.RegisterViewWithRegion("TypeSchemeRegion", typeof(SchemeAutoView)); RegionManager.RegisterViewWithRegion("TypeSchemeRegion", typeof(SchemeSingleView)); RegionManager.RegisterViewWithRegion("TypeSchemeRegion", typeof(SchemeSelectView)); 

When you open a window from the program, the following code is executed:

 var schemeView = unityContainer.Resolve<SchemeView>(); regionManager.Regions.Remove("TypeSchemeRegion"); RegionManager.SetRegionManager(schemeView, regionManager); 

(SchemeView is the most launched window) In this place all three sub-windows are in the Views list of the region, the active window (ActiveView) is SchemeAutoView. When you start the window, the contents of the SchemeAutoView pane are displayed. By pressing the corresponding RadioButton, the code is executed:

 _regionManager?.RequestNavigate("TypeSchemeRegion", new Uri("SchemeSingleView", UriKind.Relative)); 

or:

 _regionManager?.RequestNavigate("TypeSchemeRegion", new Uri("SchemeSelectView", UriKind.Relative)); 

Now, if you check the contents of the region in Debuge, the active window changes accordingly. However, nothing happens on the screen, the first active sub-window is still displayed. For all windows use one ViewModel. The most interesting thing is that the same method is used in the main application window (Shell) and everything works with a bang, and does not want to work in a separate window. What am I doing wrong?

    1 answer 1

    Found the error myself. It turns out when working with Prism, if you start a new window inside the program, which, let's say, is not in the context of the main window (Shell), you need to repeat the window registration procedure in the regions in much the same way as in the start module. Well, or at least it happened to me. So the code when starting a new window:

      regionManager.Regions.Remove("TypeSchemeRegion"); var schemeView= unityContainer.Resolve<SchemeView>(); RegionManager.SetRegionManager(schemeView, regionManager); RegionManager.RegisterViewWithRegion("TypeSchemeRegion", typeof(SchemeAutoView)); RegionManager.RegisterViewWithRegion("TypeSchemeRegion", typeof(SchemeSingleView)); RegionManager.RegisterViewWithRegion("TypeSchemeRegion", typeof(SchemeSelectView)); 

    And it is also very important to first delete the required region, then be sure to make the corresponding window Resolve. At this point, the ViewModel is bound to the window (if necessary) via the Dependency Property, then the RegionManager needs to be reinstalled and a new window is bound to the region. Further in the appropriate places, RequestNavigate works without problems.