开发者

Modifying the application page stack for back button press on WP7

I have an application that uses the web browser control to show local content on a device, this is hosted as a page in the application, it integrates well with the physical back button.

The issue I have is if I place a button in the application bar to exit the web browser and go back开发者_开发百科 to the page previous to the web browser page then the WP7 application page stack remembers this and if I start pressing the back button it will go to web browser page and start traversing the pages (in reverse) I have viewed in the browser.

Ideally what I want is the web browser page to not be included in the application page stack, can I modify the contents of the stack at runtime or force a page not to be included?

Jaime article describes the usage situation for the browser control.

http://blogs.msdn.com/b/jaimer/archive/2011/02/04/back-button-press-when-using-webbrowser-control-in-wp7.aspx


Generally it is not possible to modify the NavigationStack in Windows Phone 7.0 SDK. In Mango (7.1) you will be able to Clear your NavigationStack.

NavigationService.RemoveBackEntry();

Jesse Liberty has a very good article on this:

http://jesseliberty.com/2011/05/24/managing-the-back-stack/


The linked article shows how to add pages navigated to in the webbrowser to the back stack.

By default the navigation history of the WebBrowser control is not included in the application back stack.

It sounds as though you've added extra behaviour (to include the browser history in the page back stack) and now you want to work around it.


At first, thanks to valipour for the link provided! This solution is great, but I just want to add that in order to clear all the navigation stack you need to do the following:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    if (e.NavigationMode == NavigationMode.New
        && NavigationContext.QueryString.ContainsKey("clear"))
    {
        while (NavigationService.CanGoBack)
        {
            NavigationService.RemoveBackEntry();
        }
    }
}

If you add this code to the MainPage.xaml code-behind and launch it with /MainPage.xaml?clear=true URI, the navigation stack will be cleared.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜