Search code examples
c#wpfprism-6

Prism 6.3 Wpf : Setting regionMangers active view fails because of missing view name when registering the view


I want to set the Active View of a Region but im not able to recive the correct name of the View from RegionManger

I register the Views in a Module like this:

_regionManager.RegisterViewWithRegion("MainRegion",typeof(ViewA));
_container.RegisterTypeForNavigation<ViewA>("ViewA");          
_container.RegisterTypeForNavigation<ViewB>("ViewB");

im navigating to ViewB in the "MainRegion".

Later in some method of ViewB im trying to set ViewA as the active view of "MainRegion".

var viewA = _regionManager.Regions["MainRegion"].GetView("ViewA");
_regionManager.Regions["MainRegion"].Activate(viewA);

Im not able to get viewA here. after debugging i found the Name property of the MainRegion.Views to be empty for ViewA and ViewB.

How can i activate ViewA or how to register the views in a way to set the Name properly ?


Solution

  • You register a view for navigation like this

    _container.RegisterTypeForNavigation<ViewA>("ViewA");
    

    Then you just request to navigate using RequestNavigate:

    _regionManager?.RequestNavigate("MainRegion", "ViewA");
    

    If you want to check if a certain view is in a certain region you can do it like this:

    regionManager.Regions["MainRegion"].Views.Any(v => v.GetType() == typeof(ViewA));