×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    7

    WP back button vs OnNavigatedTo method

    Hi there,

    I have a question regarding WP back Button behavior, below is the problem:
    Suppose that I have two pages (page1 and page2), page1 have OnNavigatedTo method which
    will fire when going back page1 and set its state to s1.

    Now suppose that page1 is in state s2 (different than s1), I go to page2, then back to page1 using the back button.

    what I expect that page1 state s2 to be preserved, but actually the OnNavigatedTo method is called and it sets page1 to state s1.

    Is there anyway to avoid such behavior, I need to use the OnNavigatedTo method to preserve the state when returning from (tombstone state), but this way it is interfering with the back button?

    any ideas?

    Regards,

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: WP back button vs OnNavigatedTo method

    You could always save the state in application class when you navigate out from the page 1, then you could always easily check it when your page 1 is navigated back.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Location
    Manaus, Brazil
    Posts
    5

    Re: WP back button vs OnNavigatedTo method

    Why do you set it to s1 on Page1 OnNavigatedTo? If it should be in s1 when the page is first created, you could set it only in the constructor of Page1, then it will not be set again.
    I'd also recommend you to read about the MVVM pattern, it is perfect for Silverlight apps and it will probably make it easier to control states.

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    7

    Re: WP back button vs OnNavigatedTo method

    Thanks for the feedback,
    answering your question: Why do you set it to s1 on Page1 OnNavigatedTo?
    there are some controls like textboxes and toggleswitches which I have to save its state so that the user don't loose any info when navigating back.

    I didn't read about the MVVM pattern yet, so if my below question is "stupid" forgive me
    the real problem I'm facing is as follows:

    at t=0 page1 is in s1 (and there is backgroundworker working a method)
    at t=t1, I saved the page1 state (s1), then navigated to page2 doing some work on it ... while on page2, the background worker finished the work and it should update the UI on page 1, now page1 in (s2) but still it is not displayed.
    at t=t2, I navigated back to page1, and ofcourse it loaded s1 instead of s2 as expected (due to the OnNavigatedTo method).

    what i want is to load s2, which is created by the background worker ...
    I already solved the problem by setting some variables but i feel there is a shortcut for this situation.

  5. #5
    Regular Contributor
    Join Date
    Jan 2009
    Location
    India
    Posts
    138

    Re: WP back button vs OnNavigatedTo method

    Hello Tarhini.hassan

    See MSDN reference for How to save application states in windows phone 7 application.

    Preserve and Restore Application State for Windows Phone


    Hope it helps.
    Pavan Pareta
    Sr. Software Engineer
    http://windows-mobile-dev.blogspot.com

  6. #6
    Registered User
    Join Date
    Oct 2010
    Location
    Trivandrum ,Kerala
    Posts
    139

    Re: WP back button vs OnNavigatedTo method

    Please try the foillowing ViewModel to handle saving or restore the page's state

    protected override void OnNavigatedFrom(NavigationEventArgs e)
    {
    base.OnNavigatedFrom(e);
    // saving the page's state

    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    base.OnNavigatedTo(e);
    // restore the page's state
    }
    sreerajvr

Similar Threads

  1. Replies: 3
    Last Post: 2011-10-31, 13:37
  2. Replies: 1
    Last Post: 2010-04-25, 23:03
  3. Back Button
    By ff123 in forum Symbian
    Replies: 26
    Last Post: 2009-10-06, 07:18
  4. Replies: 4
    Last Post: 2007-11-22, 11:11
  5. back button problem
    By wenyancam in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2002-12-04, 16:09

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×