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

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

问题描述

我在 Windows 手机 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 推入 前进堆栈,因为他向后导航,并且每当他按下前进按钮时,您就会导航到 前进堆栈 中的第一个元素,并且弹出它,依此类推,直到您在前向堆栈中留下网址.一旦他导航到您未从 forward stack 导航的某个 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.

通过这种方式,您甚至可以在列表中或以您喜欢的方式显示历史网址.

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天全站免登陆