INavigationAware Question

Topics: Prism v4 - Silverlight 4
Nov 24, 2010 at 12:56 AM

ViewModel 1:

 [Export(typeof(AssessSchemeListViewModel))]
public class AssessSchemeListViewModel : NotificationObject
{

    private void Add(object para)
        {
            var builder = new StringBuilder();
            builder.Append("AssessSchemeView");
            this._regionManager.RequestNavigate("AssessSchemeListRegion", new Uri(builder.ToString(),UriKind.Relative));
        }
}

ViewModel 2:

    [Export]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    [RegionMemberLifetime(KeepAlive = false)]
    public class AssessSchemeViewModel : NotificationObject,IConfirmNavigationRequest
    {
    private void Ok()
        {
            if (this.navigationJournal != null)
            {
                this.navigationJournal.GoBack();
            }
        }

    void IConfirmNavigationRequest.ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
        {
            continuationCallback(true);
        }

        bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
        {
            return false;
        }

        void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
        {

        }

        void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
        {
          
            this.navigationJournal = navigationContext.NavigationService.Journal;
        }

}

everything is ok.  but when i change the ViewModel 1:

 [Export(typeof(AssessSchemeListViewModel))]
public class AssessSchemeListViewModel : NotificationObject, INavigationAware
{

    private void Add(object para)
        {
            var builder = new StringBuilder();
            builder.Append("AssessSchemeView");
            this._regionManager.RequestNavigate("AssessSchemeListRegion", new Uri(builder.ToString(),UriKind.Relative));
        }
        bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
        {
            return false;
        }

        void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
        {

        }

        void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
        {

        }
}

now when i navigation to View 2, it can't go back to View1. where is the problem?

Nov 24, 2010 at 5:38 AM

I think the proble is here

bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
        {
            return false;
        }


You are telling it not to participate in navigation. Try setting it to true. I think it should work.

Nov 26, 2010 at 2:21 AM

Did this get resolved for you?