INavigationTarget not being hit

Topics: Prism v4 - Silverlight 4
Jan 25, 2012 at 3:55 PM
Edited Jan 25, 2012 at 4:03 PM

Hi all

I have a viewmodel that implements INavigationAware interface.  In IsNavigationTarget I'm returning false as I would like a new view opened, but what is happening is that the same view is being displayed in the region with previous values.

This is a login screen with 2 properties(username and password).  I'm using MEF to export the viewmodel as follows:


public class LoginViewModel : BaseINPC, ILoginViewModel, INavigationAware
         //public username and password properties
         //with property changed

        public bool IsNavigationTarget(NavigationContext navigationContext)
            return false;


My loginview.cs is as follows:
    public partial class LoginView : UserControl
        public ILoginViewModel ViewModel
            set { this.DataContext = value; }

        public LoginView()
When loading the loginview I use the following:But the problem arises 
when the user logs out, I want to show the loginview so I requestnavigate to the view:
_regionManager.RequestNavigate("MainRegion", "LoginView");

The view loads but the values for username and password are still the values from the 
first time the loginview was loaded so I'm not getting a new view/viewmodel.
I put a breakpoint in the IsNavigationTarget but it's not been hit.
This must be something simple, looked at other posts regarding contract names etc 
but to no avail, any help much appreciated.
ps tried to fix formatting but no luck.
Jan 25, 2012 at 4:35 PM


I believe that your problem could be related to the fact that your LoginView is exported as a singleton (as this is the default behavior in MEF). Therefore, each time you perform navigation the container returns the same instance of this view.

Based on this, you could try including [PartCreationPolicy(CreationPolicy.NonShared)] attribute also in the LoginView view.

I hope you find this helpful,

Agustin Adami

Jan 25, 2012 at 5:13 PM

Agustin to the rescue yet again :)

Thanks that was it, new it was something simple but couldn't see the wood from the trees.