Kuthay Gumus
Kuthay Gumus

Reputation: 764

Windows Phone 8: Back Button

I'm new on windows phone platform. I'm trying to make a news application. On this application, user clicks and reads the article of news, after, user wants to came back to mainpage to see all news headers again, and will click the other news again.

But when the user comes back to mainpage after reading first article, user clicks second news header. But when user navigates to new page, first news article is still there.

I wanna ask this, is there any back button for user (after reading first news article) to use for clearing cache of article page when he or she presses to come back mainpage ?

I used this but it doesnt;

private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}

I wrote something under my httprequest, but it didnt worked for me too;

private void LiveLongListSelector_Loaded(object sender, RoutedEventArgs e)
{
    string url = "MYWEBAPIURL&rnd=" + new Random().Next(1,1000);
    HttpWebRequest hWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
    hWebRequest.Method = "GET";
    hWebRequest.BeginGetResponse(ResponseLive_Completed, hWebRequest);
    hWebRequest.Headers[HttpRequestHeader.CacheControl] = "no-cache";
    hWebRequest.Headers[HttpRequestHeader.CacheControl] = "no-cache";
    hWebRequest.Headers["Cache-Control"] = "no-cache";
    hWebRequest.Headers["Pragma"] = "no-cache";
}

Can anyone help me to find that perfect back button or other thing ?

Thank you very much

Upvotes: 2

Views: 3325

Answers (3)

Kunal Chowdhury
Kunal Chowdhury

Reputation: 91

I will suggest to use the following code in NavigatedTo() method:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    while (NavigationService.RemoveBackEntry() != null);
}

Hope, that helps.

Upvotes: 0

Raj
Raj

Reputation: 51

Simply use NavigationService.GoBack(); instead of using

NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));

It will clear all catch automatically.

or you can use NavigationService.RemoveBackEntry(); when coming again to read second article. Use something like-

int a = NavigationService.BackStack.Count();
while (a > number) //number is stack count when comes to main page first time
{
     this.NavigationService.RemoveBackEntry();
     a = NavigationService.BackStack.Count();
}

Upvotes: 5

Pavel Saniuk
Pavel Saniuk

Reputation: 788

There are two methods on PhoneApplicationPage that you can override and clean a cache: OnNavigatedTo and OnNavigatedFrom.

Upvotes: 0

Related Questions