How to finish current page in Windows Universal

2019-06-04 18:48发布

问题:

How can I close the current active Page in UWP development?

I want to start a new Page and close the current one, so the user cannot go back to that page. Is there any method in UWP similar to Android's method "finish()"?

回答1:

I think you should be able to do this by removing last page from back stack after navigating to a new one. Sample code in OnNavigatedTo of a new page:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    this.Frame.BackStack.RemoveAt(this.Frame.BackStack.Count - 1);
}

This should prevent user from going back to last page. Of course you can modifay the back stack in many ways if you need.