RequestNavigate not creating view first time if IsNavigationTarget return true

Aug 28, 2012 at 9:27 PM
Edited Aug 28, 2012 at 9:29 PM

Hi,

I have an abstract class I have implemented INavigationAware. In abstract class I also have a virtual method AlreadyExists() that the drived classes can implement to have their own logic for checking if the view already exists or not. In my abstract class I call AlreadyExists() method in IsNavigationTarget to give me true or false so that the derived implementation of AlreadyExists gets called automatically by base class and  each derived class should not have to write this code in it and its happening correctly. But with this the problem that I am having is RequestNavigate doesn't create a view even at 1st time.

It could be an oop design issue but would really appreciate any help.

Thanks.

 

public abstract class UserControlBase : UserControl, INotifyPropertyChanged, INavigationAware
    {
        public virtual bool AlreadyExists()
        {
            return false;
        }
        public virtual bool CanShutdown()
        {
            return true;
        }
        public virtual void Shutdown()
        {
        }

        #region INavigationAware members
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            //IsNavigationTarget is not invoked 1st time as it should be but view is 
	    //not even 1st timecreated
	    //every next time, derived class's AlreadyExists gets called but view is 
    	    //still not created
            bool temp = AlreadyExists();
            return temp;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
        }
        #endregion INavigationAware members

        #region INotifyPropertyChanged members
        ...
        #endregion
    }

PS: Im using Prism 4.1, MEF, .net 4.5.

Aug 29, 2012 at 7:26 PM

My fault. Before using INavigationAware interface, I have restricting creation of new view in my custom region adapter. Just cleaned that code and it started working.

Moderator feel free to remove this discussion if you want.

Thanks.