WPF 浏览器控件与 winforms [英] WPF webbrowser control vs winforms

查看:24
本文介绍了WPF 浏览器控件与 winforms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 wpf 应用程序,我在其中使用了 webbrowser 控件.无论如何,有时我需要查找 html 元素、调用点击和其他基本功能.

I am creating a wpf application where I am using a webbrowser control. anyways sometimes I am required to look for html elements, invoke clicks, and other basic functionality.

在 winforms webbrowser 控件中,我可以通过以下方式实现:

In winforms webbrowser control I am able to achieve this by doing:

 webBrowser1.Document.GetElementById("someId").SetAttribute("value", "I change the value");

在 wpf webbrowser 控件中,我设法通过以下方式实现了相同的目的:

In wpf webbrowser control I managed to achieve the same thing by doing:

  dynamic d = webBrowser1.Document;  
  var el = d.GetElementById("someId").SetAttribute("value", "I change the value");

我还设法使用动态类型在 wpf webbrowser 控件中调用了单击.有时我会得到例外.

I also managed to invoke a click in the wpf webbrowser control by using the dynamic type. Sometimes I get exeptions though.

如何在 wpf 网络浏览器控件中查找 html 元素、设置属性和调用点击,而不必使用经常出现异常的动态类型?我想用 wpf webbrowser 控件替换 wpf 应用程序中的 winforms webbrowser 控件.

How will I be able to look for html elements, set attributes and invoke clicks in a wpf webbrowser control without having to use dynamic types where I often get exceptions? I will like to replace my winforms webbrowser control in my wpf application by a wpf webbrowser control.

推荐答案

我这样做的方式是...

The way I have done this is...

使用 HTTPRequest 下载要呈现的页面的 HTML 文本.在 HTML 文本中使用 HTML 敏捷包注入 java 脚本.如果你想使用 jQuery,那么你必须先 jQuerify 你的页面,然后用你的 dom 元素绑定事件.您还可以从脚本内和其他方式调用您的 c# 函数.没有搞乱动态类型,因此也不例外.

Download HTML text of the page you want to render using HTTPRequest. Inject java script using HTML agility pack in HTML text. If you want to use jQuery then you have to jQuerify your page first and then bind event with your dom elements. You can also call your c# function from within the script and other way around. No messing around with dynamic types and hence no exception.

您还可以使用此链接.

这个这个 可能会有所帮助.

这篇关于WPF 浏览器控件与 winforms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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