0
this.Frame.Navigate(typeof(SomeClass), file);
this.Frame.GoBack();

Hello guys,

Goback() method is creating a new instance, but i do not want it.I want the previous page stay how i left, and keeps data. Any idea about that issue?

alidrsn
  • 109
  • 1
  • 10
  • This may help: http://stackoverflow.com/questions/11539755/winrt-uwp-frame-and-page-caching-how-to-create-new-page-instance-on-navigate – Rico Suter Apr 10 '16 at 22:33

3 Answers3

2

You have to set the NavigationCacheMode property:

public MainPage()
{
    InitializeComponent();
    NavigationCacheMode = NavigationCacheMode.Enabled;
}
Mirko Bellabarba
  • 562
  • 2
  • 13
0

In App.xaml.cs you should be setting the size of the frame's page cache. Add the line that sets the CacheSize after the NavigationFailed handler is assigned.

rootFrame = new Frame();

rootFrame.NavigationFailed += OnNavigationFailed;

// Add this line after the above 2 lines that already exist.
rootFrame.CacheSize = 2; // Or some other number that makes sense for your application

On the page where you want to retain data, in the XAML set the cache mode to required.

<Page ... NavigationCacheMode="Required" >...</Page>

In your codebehind, you may need to override OnNavigatedFrom and OnNavigatedTo to save and restore state.

If you do not want to retain data, set NavigationCacheMode="Disabled" on that page. You still navigate using Frame.Navigate(typeof(SomePage));

Max Hampton
  • 1,254
  • 9
  • 20
0

you can serialize all your data of your viewmodel or class and restore or save the data to recover the previous information.

here is an example.

http://irisclasson.com/2012/07/09/example-metro-app-winrt-serializing-and-deseralizing-objects-to-storagefile-and-localfolder-using-generics-and-asyncawait-threading/

RicardoPons
  • 1,323
  • 9
  • 14