如何在Wp7应用程序中处理Web浏览器的前后导航 [英] How to handle a Web Browser back and forward navigation in a Wp7 app

查看:53
本文介绍了如何在Wp7应用程序中处理Web浏览器的前后导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows Phone 7应用程序中使用网络浏览器.我只想知道,像任何桌面浏览器一样,如何处理其后退和前进导航.还有如何阻止特定的导航.

I am using a web-browser in my windows phone 7 application. I just want to know that how to handle its back and forward navigation just like any desktop browser. And also how to block a particular navigation.

我在此处引用了和其他许多内容,但找不到对我有用的任何内容.请帮忙.

I referred here and many others but couldn't find anything working for me. Please help.

推荐答案

要使其像桌面浏览器一样工作,您可以实现 stack .

To make it work like a desktop browser you can implement a stack.

您将前后放置两个按钮.当用户在浏览器中导航到下一个 URL 时,您将其推入历史记录堆栈,当他想通过按返回按钮返回时,您导航到历史记录堆栈中的第一个URL以编程方式从历史记录堆栈中将其弹出,这样他就可以向后导航,直到堆栈中包含一些 URL .同样,对于前进,您在导航时将 URL 推入前进堆栈,并且每当他按下前进按钮时,您导航到前进堆栈中的第一个元素,然后弹出,依此类推,直到您将网址保留在转发堆栈中为止.一旦他导航到您未从前向堆栈导航的某个网址,您就清空前向堆栈,并在他向后移动时再次填充.

You will put two buttons back and forward. As the user navigate to next URL in browser you push them into history stack and when he wants to get back by pressing back button you navigate to the first url in the history stack programmatically and pop it up from the history stack so he can navigate back till stack has some URLs in it. Similarly for forward you push URLs into forward stack as he navigates back and and whenever he presses forward button you navigate to first element in forward stack and pop it up and so on till you have urls left in forward stack. Once he navigates to some url which is not navigated from forward stack by you then you empty the forward stack and fill it again when he moves back.

通过这种方式,您甚至可以在列表中显示历史记录URL,也可以随意显示.

This way you can even show history urls in a list or however you like.

关于导航取消,这是您问题下方的注释中指向问题的链接的代码,

About navigation cancel, here is the code from the link to question in the comments under your question, it should work.

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    //cancel navigation
     e.Cancel = true;

}

这篇关于如何在Wp7应用程序中处理Web浏览器的前后导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆