View Base Navigation Not taking place.

Topics: Prism v4 - Silverlight 4
Aug 5, 2013 at 1:16 AM
Edited Aug 5, 2013 at 1:18 AM
Hi to all friends out there.

I am not able to acheive iew base navigation . In my application i have to change view in region and this i need to achieve with navigation.

Below is my code.

public class StartUpScreenViewModel : IRegionMemberLifetime
    public IUnityContainer appContainer ;
    public IRegionManager appRegionMngr ;
    public bool KeepAlive
        get { return true; }

    public StartUpScreenViewModel()
        appContainer = ServiceLocator.Current.GetInstance<IUnityContainer>();
        appRegionMngr = ServiceLocator.Current.GetInstance<IRegionManager>();

    private void registerViews()

        appContainer.RegisterType<object, Register>("register");
        appContainer.RegisterType<object, AuthenticatedUser>("Authenticated");
        appContainer.RegisterType<object, Authenticate>("Authenticate");
        appContainer.RegisterType<object, StartUpScreen>("StartUpScreen");
and on linkbutton i bind this delegate having this method.

regionmngr.RequestNavigate("mainRegion", new Uri("register", UriKind.Relative));

whenever i click on button, view do not changes. It remain same. Even i checked with callback method of navigation but there is no error and nothing.

So can you please tell me what i am doing wrong which is not letting my view to change.I need to show one view at time.

Thanks in advance.
Aug 5, 2013 at 7:12 PM
Edited Aug 6, 2013 at 5:24 PM
Hello PankajGoswami,

As far as I can see on the code you provided everything seems to be on the right track.
Please verify that:

  • The RequestNavigate call is being performed. Assuming you are using a command, the issue might be related to an incorrect binding.
  • The StartUpScreenViewModel class is instantiated before the RequestNavigate() call occurs. Otherwise, the view won’t be registered in the container.
Notice that the mainRegion should be a SingleActiveRegion (use a ContentControl), which only display one view at the same time.
Is there a reason why you are performing the views registrations into the container from the view model, instead of doing it when the module is initialized?

If the above does not help, please send a small repro sample (or code that provides more context) so I can troubleshoot the cause for the issue.

I hope this helps,

Gabriel Ostrowsky
Aug 13, 2013 at 11:57 AM
Thanks for your reply.
Here is my sample project for navigation. In this my application view gets changed form menu.

I am not able to figure out why it is not working. Even i did on Module as you had mentioned.

Here is link from where you can download the navigation sample.

In this i want to load one view when its loads and gets changes form menu by clicking them. I register my views in ModuleClass.

please let me know also what wrong i was doing.
Looking forward to your reply.
Aug 13, 2013 at 6:16 PM
Hi Pankaj,

After checking your sample we found the following problems:

  • The region defined in the Shell is named as "mainRegion", but when invoking the request navigate you are passing the region name as "mainregion" instead.
  • The register view was registered with the name of "register" in the container, but in the navigation request you are asking for a "registerView" instead. Those names need to be the same in order for the navigation to work.
  • The "mainregion" defined in the Shell is an ItemsControl. By default, regions based on ItemsControls cannot deactivate views and therefore they will always show all the views they contain. If you wish to show only one view at a time you will need to use a ContentControl instead.
  • Also, the "main" and "menu" regions were defined on the first row of the Grid, which caused them to overlap. This can be changed by adding the property Grid.Row=”1” on the main region tab item.
You can find a modified version of your sample with the aforementioned fixes made by Gabriel in the following link:
Hope this helps,

Damian Cherubini
Aug 14, 2013 at 1:28 PM
Thanks for reply.
It works.I need to ask one thing also that does ContentControl creates new control every time ? when required view is loaded in region than any view which were present get deactivated by default?And what if i need to persist the value of view.

Just these are few points which i want to get cleared .

Thanks in advance.
Aug 14, 2013 at 9:55 PM

Based on my understanding a region based on a ContentControl only maintains one active view at the same time. Therefore, during navigation any previous views in the region will be deactivated. If you want to maintain a deactivated view alive inside the region, you can make it implement the IRegionMemberLifetime interface in its view model and return true in its KeepAlive property. If you wish to reuse an existing view that is being kept alive in the region, you can make it implement the INavigationAware interface. If its IsNavigationTarget method returns true, the region will navigate to the existing view. If it returns false, a new view will be used instead.

Also, in order for this to work correctly you need to register the views in the container using the exact name of the view type. For example:
appContainer.RegisterType<object, AuthenticatedUser>("AuthenticatedUser");
Hope this helps,

Damian Cherubini