locked
Troublel Navigating to different PageFunction<T> pages RRS feed

  • Question

  • I am having trouble navigating do different PageFunction<T> pages in my Wizard.

    I am using WPF and the Composite Application Guidance framework.  The Wizard works great except when I use conditional code in one of my pages (Page2) to determine which page to go to next.  I new up a PageFunction<T> to navigate to one page, navigate to it succesfully using NavigationService.Navigate(Page2a), and then navigate from Page2a back to Page2, the one that called it, using NavigationService.GoBack().  That works fine.  Then I want to navigate to a different page because the condition has changed.  I new up PageFunction<T> Page3 and want to use NavigationService.Navigate(Page3).  But because there is an entry in the NavigationService, NavigationService.CanGoForward is true, to I use NavigationService.GoForward() to navigate forward, which takes me to Page2a.

    I decided not to use NavigationService.GoForward(), but to always use NavigationService.Navigate(Page2a or Page3) based on the condition. 

     

     

    if (AutoPathConfiguration)
    {
        if (Step3 == null)
       {
           Step3 =
    new Step3((Data)this.DataContext);
           Step3.Return +=
    new ReturnEventHandler<DesignResultEnum>(WizardPageReturn);
        }
        this.NavigationService.Navigate(Step3);
    }

     

     

    else

    {

        if (Step2a == null)
        {
            Step2a =
    new Step2a((Data)this.DataContext);
            Step2a.Return +=
    new ReturnEventHandler<DesignResultEnum>(WizardPageReturn);
         }
            this.NavigationService.Navigate(Step2a);
    }

     

     


    That's when I get ="A PageFunction object cannot be started again before it has returned."  Googling this I find a hit that says to either to new up a new Page2a or Page3 each time you navigate, which works, but I need to keep the page around, or to subclass Page, not use PageFunction<T>, and do it yourself.

    I did not subclass Page, but just used Page instead of PageFunction<T> and all my problems went away.  However, I do not know how to cancel out of any page or to close down the Wizard.  I am using a Frame class, setting its content to the calling page, which news up the first page and Navigates to it.  I don't think I can use NavigationWindow in the Composite Application Framework, which has a Close() method on it and would close down the Wizard.

    I have spent alot of time trying to figure out both solutions and have not found success.  Any ideas what I need to do?

    Thanks.

    Tuesday, February 9, 2010 8:01 PM

Answers

  • Hello John,

    When you are done with Page2a, you should call OnReturn to return from Page2a to Page2 instead of NavigationServices.GoBack(). That's how a PageFunction<T> returns to its caller page. And by default, when a PageFunction<T> returns, it will be removed from journal unless the RemoveFromJournal property is set to False.

    In case you haven't read it before, here is the link to the Structured Navigation Overview.

    Hope this helps.

    Regards,
    Jie
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The All-In-One Code Framework Project
    My Blog (in Simplified Chinese)
    • Marked as answer by John C C Friday, February 12, 2010 1:09 AM
    Thursday, February 11, 2010 6:37 AM
  • Jie,

    I did some more experimenting.  I am not newing up a new PageFunction<T> each time I go navigate forward, as show in my original question. Because it is not new, I get the error of "A PageFunction object cannot be started again before it has returned." It is as though something is not reset in the PageFuction<T> class and Navigate can't use it.  In another post another moderator said "The error message is a little confusing here... what it means is that a PageFunction that HAS successfully returned must be "recycled" before reuse."  Apparently there is no supplied mechanism to "recycle" it.

    If I new up a PageFunction<T> each time I navigate forward and use OnReturn(), everything works fine.

    Thanks,
    John

    • Marked as answer by John C C Friday, February 12, 2010 1:09 AM
    Thursday, February 11, 2010 9:31 PM

All replies

  • Hello John,

    When you are done with Page2a, you should call OnReturn to return from Page2a to Page2 instead of NavigationServices.GoBack(). That's how a PageFunction<T> returns to its caller page. And by default, when a PageFunction<T> returns, it will be removed from journal unless the RemoveFromJournal property is set to False.

    In case you haven't read it before, here is the link to the Structured Navigation Overview.

    Hope this helps.

    Regards,
    Jie
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The All-In-One Code Framework Project
    My Blog (in Simplified Chinese)
    • Marked as answer by John C C Friday, February 12, 2010 1:09 AM
    Thursday, February 11, 2010 6:37 AM
  • Jie,

    Thank your for the reply.  I swapped out the NavigationService.GoBack with OnReturn(...) and still get the "A PageFunction object cannot be started again before it has returned." error.  I do not have RemoveFromJournal set to false.  I am baffled.

    Since I wrote, I rolled my own by subclassing the Page class and putting my own Return event and OnReturn method in there.  I use a Frame class as a host and when I cancel out or finish with the wizard, I set the Frame.Content = null to "close" the wizard.  I also remove all the back entries.

    Thanks,
    John

    Thursday, February 11, 2010 8:58 PM
  • Jie,

    I did some more experimenting.  I am not newing up a new PageFunction<T> each time I go navigate forward, as show in my original question. Because it is not new, I get the error of "A PageFunction object cannot be started again before it has returned." It is as though something is not reset in the PageFuction<T> class and Navigate can't use it.  In another post another moderator said "The error message is a little confusing here... what it means is that a PageFunction that HAS successfully returned must be "recycled" before reuse."  Apparently there is no supplied mechanism to "recycle" it.

    If I new up a PageFunction<T> each time I navigate forward and use OnReturn(), everything works fine.

    Thanks,
    John

    • Marked as answer by John C C Friday, February 12, 2010 1:09 AM
    Thursday, February 11, 2010 9:31 PM