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

吃可爱长大的小学妹 提交于 2020-01-11 12:21:24

问题


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.


回答1:


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




回答2:


try this code

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

Source enter link description here



来源:https://stackoverflow.com/questions/23127788/how-to-reload-a-windows-phone-application-page-without-creating-a-new-copy-in-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!