Mohana Krishna G
Mohana Krishna G

Reputation: 431

How to reload a Windows phone application page without creating a new copy in the memory?

In my Windows phone application, I'm trying to reload the application page by using the following code:

NavigationService.Navigate(new Uri(string.Format("/Page1.xaml?random={0}", Guid.NewGuid()), UriKind.Relative));

I have written the code above to the button click event. The Page1 is reloading fine but every time when I click the button the app memory keep on increasing and at some time app is crashed.

Is there any other way to reload or refresh the page with out creating a new copy of the page in the app memory.

Upvotes: 1

Views: 3561

Answers (2)

DrUalcman
DrUalcman

Reputation: 1

try this code

var Frame = Window.Current.Content as Frame;
Frame.Navigate(Frame.Content.GetType());
Frame.GoBack();

Source enter link description here

Upvotes: 0

Nahuel Ianni
Nahuel Ianni

Reputation: 3185

You can always refresh the content of the page from code by calling Page.Refresh(); or some similar method, but this may not refresh all the content.

If you decide to do a new navigation (and ensure that everything gets to the initial state of the page), you can remove the previously navigated pages from the stack by calling:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
   if (NavigationContext.QueryString.ContainsKey("logedin"))
   {
       NavigationService.RemoveBackEntry();
   }
}

Take a look at the NavigationService class, specially the AddBackEntry and RemoveBackEntry methods:

http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationservice(v=vs.110).aspx

Upvotes: 1

Related Questions