简体   繁体   中英

Remove the current page from the navigation stack and WebBrowserTask

I have a page that calls a WebBrowserTask. When the user is returning from the browser, I don't want to show the page that launched the task, but the previous one.

The problem is that the Navigation stack does not contain the current page, and I have no way to remove it from the entries in the page, and the WebBrowserTask doesn't allow us to do anything.

On Android, I can specify for a given Activity to not be added in the back stack. Is there something like this ?

Currently, the only way that I have found to almost do what I want is to set a flag when I call the task, and check it in the OnNavigatedTo handler of the page. But the page is still visible a few seconds before going back. It's not good.

Thanks.

I have not tested this, but you might be able to do the following

bool navigatedFromBrowser;
public MainPage()
{
    navigatedFromBrowser = false;
}
public void someMethod()
{
    WebBrowserTask webBrowserTask = new WebBrowserTask();
    webBrowserTask.Uri = new Uri("http://msdn.microsoft.com", UriKind.Absolute);
    webBrowserTask.Show();
    navigatedFromBrowser = true;
}
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
    if(navigatedFromBrowser && NavigationService.CanGoBack)
    {
        navigatedFromBrowser = false;
        NavigationService.GoBack();
    }

}

It might be an ugly way of doing it, but it might work. navigatedFromBrowser should keep it's value because it will be the same instance of the page when navigated back from the broswer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM