locked
Recover data on a Previous Page after navigating from the page and navigating back RRS feed

  • Question

  • How can i recover the data on Page1 after navigating to Page2, so that when i navigate to Page1 from Page 2 i want the unsaved data as is.
    Friday, September 24, 2010 1:52 PM

Answers

  • To complement the answer of Bob, I will quote a Tip from the excellent book "SAMS - WPF Unleashed":

    "When navigating to a Page via a URI (whether done by calling the Navigate method or by using a Hyperlink), a new instance of the
    Page is created, even if you’ve already visited it.
    Therefore, you need to maintain your own state (via static variables or Application.Properties, for example) if you want a page to “remember” its data. 
    (When calling an overload of Navigate that accepts a Page instance, of course, you’re in control of whether a new or old instance is used.)
    In the case of journal navigation, however, you can force a Page to reuse the same instance by setting its JournalEntry.KeepAlive attached property to true."

    Hope it helps

     

    Federico Colombo

    • Proposed as answer by Jie Bao Saturday, October 2, 2010 4:21 AM
    • Marked as answer by Jie Bao Monday, October 4, 2010 11:25 AM
    Saturday, October 2, 2010 3:17 AM

All replies

  • Okay this is what i have found out.

    On Page 1 i have controls txtBox, ComboBox and a hyperlink. TextBox has Value "ABC" ComboBox has some value "123"

    When i click on the Hypoerlink i Navigate to page2.

    On Page2 i click on a btnGoBack which takes me back to Page1. I can actually see my values.

    I however cannot see the values when the controls on Page1 are bound to a datasource.

    ex: in XAML

    if i have <TextBox: x:Name="txtName" Text={Binding Path = uName"}/>

    Then in the Page navigation to Page2 and back it is not retaining the value in the text box and the Combo Box.

    Is this some kind of intended behaviour or a bug?

     

    Monday, September 27, 2010 3:41 PM
  • Hi NewtoLinq,

    Please set the Page1.KeepLive to True that can save the status of the controls in the Journal. For more about the Page lifetime, please refer to the Navigation Overview: http://msdn.microsoft.com/en-us/library/ms750478.aspx and read the "Navigation Lifetime" section.

    Sincerely,
    Bob Bao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download all in one code framework !
    • Proposed as answer by thepirat000 Saturday, October 2, 2010 3:08 AM
    Thursday, September 30, 2010 10:09 AM
  • @Bob,

    I appreciate you trying to help.

    But please read my question throughly and then read the post that you want me to read and reply back.

     

    Becasue i read the post 1000 times and i can't see any solutiuon.

     

    Friday, October 1, 2010 3:59 PM
  • To complement the answer of Bob, I will quote a Tip from the excellent book "SAMS - WPF Unleashed":

    "When navigating to a Page via a URI (whether done by calling the Navigate method or by using a Hyperlink), a new instance of the
    Page is created, even if you’ve already visited it.
    Therefore, you need to maintain your own state (via static variables or Application.Properties, for example) if you want a page to “remember” its data. 
    (When calling an overload of Navigate that accepts a Page instance, of course, you’re in control of whether a new or old instance is used.)
    In the case of journal navigation, however, you can force a Page to reuse the same instance by setting its JournalEntry.KeepAlive attached property to true."

    Hope it helps

     

    Federico Colombo

    • Proposed as answer by Jie Bao Saturday, October 2, 2010 4:21 AM
    • Marked as answer by Jie Bao Monday, October 4, 2010 11:25 AM
    Saturday, October 2, 2010 3:17 AM
  • Hi NewtoLinq,

    Sorry for not do a detailed explaination. Perhaps, you could refer to my other thread, http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/2ed6ae96-7b05-4c92-9da0-07c1a03a2899

    And thanks, thepirat000.

    Sincerely,
    Bob bao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download all in one code framework !
    Saturday, October 2, 2010 4:21 AM