如何在 Windows Phone 7 中从 javascript 调用 ac# 方法?
我想使用 JavaScript 检测 C# 中 Web 浏览器控件中的滑动。我想向我的 Web 内容添加一些 JavaScript,然后如果发生滑动,则调用在同一 Web 浏览器控件中加载另一个 Web 内容的方法。
我想要一些示例代码或任何其他建议来执行此操作。
提前致谢
I want to detect swipe in web browser control in C# using JavaScript. I want to add some JavaScript to my web content and then if swipe occurs, call a method that loads another web content in the same web browser control.
I would like some sample code or any other suggestion to do this.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用一些东西来检测 JavaScript 中的滑动。有人建议我使用 touch.js 但还没有机会尝试这个。
当您检测到滑动时,可以使用
window.external.notify()
调用本机代码。请务必在 WebBrowser 控件上设置
IsScriptEnabled="True"
并为ScriptNotify
事件注册处理程序。这个事件处理程序将加载新内容。
You'll need to use something to detect the swipe in javascript. I've been recommended to use touch.js but haven't had a chance to try this yet.
When you detect the swipe you can call out to native code using
window.external.notify()
.Be sure to set
IsScriptEnabled="True"
on the WebBrowser control and register an handler for theScriptNotify
event.It's this event handler which would load the new content.
首先,考虑网络浏览器控件的手势有它自己的处理程序。现在,如果您不需要在网络浏览器控件中进行平移/缩放等操作,那么这不是问题。
然后,您只需将
IsHitTestEnabled
属性设置为 false,以便 Web 浏览器不再接收输入。然后,您可以简单地使用 Silverlight Toolkit 中的GestureService
来处理滑动/轻拂输入。我在另一个问题中编写了一些关于如何处理此问题的代码: wp7 水平滑动选择
First of all, consider that gestures for a webbrowser control have it's own handlers. Now, if you don't need to pan/zoom or the like in the webbrowser control, it's not a problem.
Then you simply set the
IsHitTestEnabled
attribute to false, so that the web-browser no longer receives input. Then you can simply use theGestureService
from the Silverlight Toolkit to handle the swipe/flick inputs.I wrote some code on how to handle this, in another question: wp7 horizontal swipe selection