Gregg Gregg - 2 months ago 14
C# Question

Skipping Page while clicking back button - windows phone 7

I have a project where I've got one page which takes you to adding item page and then after you add item it takes you back to the starting page. When user clicks back button it takes him back to the adding page and I would like to avoid this behaviour. So I've written that code and put it in my adding page:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.NavigationMode == NavigationMode.Back)
{
NavigationService.GoBack();
}
}


and it works almost fine cause when user clicks back button he's taken to the start page but that adding page appears for two seconds and my question is how to avoid this appearance?

Answer Source

If you want to skip the previous page, just remove it from the back stack before triggering the navigation:

// After the user has clicked on the button, remove the intermediate page before going back:
this.NavigationService.RemoveBackEntry();
this.NavigationService.GoBack();