C# Prism .RequestNavigate does not update View

910 Views Asked by At

I have lots of pain with RequestNavigate. Here is my code

public static void Navigate(this IRegionManager regionManager, Type type)
    {
        regionManager.RequestNavigate("MainRegion",
            type.FullName,
            result =>
                {
                });            
    }

In callback result.Error is null.

The number of ActiveViews in RegionManager is changing correctly. The needed view is marked as active. But visually nothing changes.

I made an experiment removing all views before RequestNavigate

    regionManager.Regions["MainRegion"].RemoveAll();

and got visual update, so everything is registered correctly, but I need my view model to keep alive.

1

There are 1 best solutions below

0
On

If you register the view type for navigation with your container:

public class ModuleAModule : IModule
{
    IUnityContainer _container;
    IRegionManager _regionManager;

    public ModuleAModule(IUnityContainer container, IRegionManager regionManager)
    {
        _container = container;
        _regionManager = regionManager;
    }

    public void Initialize()
    {
        _container.RegisterTypeForNavigation<ViewB>();
    }
}

...you can navigate to it like this:

public static void Navigate(this IRegionManager regionManager, Type type)
{
    regionManager.RequestNavigate("MainRegion",
        new Uri(type.Name, UriKind.Relative),
        result =>
        {
        });
}