locked
how to keep the data available during the navigation between the 2 pages ?

    Question

  • i had 2 xaml pages in my windows 8 app, each page has its own variables declared &  its own textboxes, when i perform an operation in page 1 the result is displayed to the textbox of page 1 but when i navigate to page 2 & come back to page 1 again i see that the textbox in page 1 is empty, is there any solution to keep the data persist even when we are navigating between pages ?  
    Sunday, August 10, 2014 2:02 PM

Answers

  • i found this simple fix & it solved my issue 
    NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;

    • Marked as answer by kranthi88 Monday, August 11, 2014 4:34 AM
    Monday, August 11, 2014 4:33 AM

All replies

  • Hi,

    try to create context object (own class) that will hold the data from first page, and use this class as second parameter on call Frame.Navigate. This on second page you will receive this data in OnNavigateTo event handler. And then use the same way to return on first page with textbox data. Bad news is, you have to set data from and to your page manually.

    Sunday, August 10, 2014 4:35 PM
  • Actually when you move to the next page, the previous page content is removed and a new instance is created everytime you come back to the very page you started from. For example, if you write this code 

    var dialog = new MessageDialog("A new instance has been created!").ShowAsync();

    ..inside the main class block of your Application. You will see that this executes each time you visit the Main Hub Page of your application. Denoting that you're actually looking at the new instance of the Hub Page. You always loose the previous related content. 

    There are many other methods, like Application Data kind of stuff. But I would like to ask you, to, as you're just a beginner. To simply just add a file with the name of the application and save the data that you wrote in the TextBox control. Once you've saved your data in that file. When you will come back, load the data from the file. 

    This is just one way of doing this. There are million of other ways and on the Windows Developer website you might find another way of doing so. But this is an easy way of doing this.


    ~!Firewall!~


    Sunday, August 10, 2014 9:00 PM
  • i found this simple fix & it solved my issue 
    NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;

    • Marked as answer by kranthi88 Monday, August 11, 2014 4:34 AM
    Monday, August 11, 2014 4:33 AM