WPF WebBrowser - 如何缩放内容?
尝试在 WPF(C#/XAML、.NET 4.0)Web 浏览器应用程序中测试基本浏览器概念。到目前为止,唯一的问题是以编程方式缩放。有人有这方面的经验吗?
MSDN 未列出任何内容: http://msdn.microsoft.com /en-us/library/system.windows.controls.webbrowser.aspx 此外,我尝试了各种方法,例如 RenderTransform 选项,但无济于事。这要么不可能,要么没有记录。我希望是后者。请注意,WinForm 解决方案是不可接受的。
预先感谢您的任何帮助, 比姆斯
Trying to test basic browser concepts in a WPF (C#/XAML, .NET 4.0) WebBrowser application. So far, the only problem is programatically zooming. Has anyone had any experience with this?
MSDN lists nothing: http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx
Additionally, I have tried various things such as RenderTransform options to no avail. Either this is not possible or not documented. I'm hoping for the latter. Note that a WinForm solution isn't acceptable.
Thanks in advance for any help,
Beems
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许你可以像这样执行 JavaScript。
在WPF中我们可以操作文档。我为你创建了一个扩展方法,这样你就可以设置缩放:
用法:
Maybe you can execute a javascript like this.
In WPF we can manipulate the document. I Created a Extension Method for you, so you can set the Zoom:
Usage:
我使用了这个答案中的点点滴滴https://stackoverflow.com/a/7326179/17822来协助缩放问题。这里的关键是ExecWB方法。 Windows 桌面上的缩放比例与 WebBrowser 控件上的缩放比例不是 1-1。你将不得不玩它。等式的伪代码如下所示:
请注意,您将需要对 SHDocVw.dll 的引用,对于 x64 计算机,它可以在 C:\Windows\SysWOW64 中找到;对于 x86 计算机,可以在 C:\Windows\System32 中找到。
这并不漂亮,但这是我发现的唯一东西,除了升级到 http://awesomium.com 实际上将 IE 默认缩放设置(默认为 Windows 桌面缩放)与 WebBrowser Control 相匹配。另请注意,Windows 桌面缩放仅适用于 Vista、Win 7,可能还存在于控制面板中的 2k8 -->显示,但我没有检查Vista或2k8。 XP(任何服务包)都没有它。
为了获得 Windows 桌面缩放(出于某种原因,这在 XP 上确实有效),我这样做了:
此逻辑被放置在该 XAML 窗口的 OnSourceInitialized 重写中。
I used bits and pieces from this answer https://stackoverflow.com/a/7326179/17822 to assist with the zoom issue. The key here is the ExecWB method. The zoom on the Windows Desktop is not 1-1 to the zoom on the WebBrowser Control. You will have to play with it. The pseudo-code for the equation looks like this:
Note that you will need a reference to SHDocVw.dll which can be found in the C:\Windows\SysWOW64 for x64 machines and in C:\Windows\System32 for x86 machines.
This is not pretty, but it is the only thing that I have found, short of upgrading to http://awesomium.com that actually matches IE default zoom settings (which default to the Windows Desktop zoom) to WebBrowser Control. Also note that the Windows Desktop Zoom only exists for Vista, Win 7 and probably 2k8 as well in the Control Panel --> Display, but I didn't check Vista or 2k8. It is not there for XP (any service pack).
To get the Windows Desktop Zoom (this does work on XP for some reason) I did:
This logic is placed in the OnSourceInitialized override for that XAML Window.
您可以看到:
http://chriscavanagh .wordpress.com/2010/10/04/a-real-net-4-0-webbrowser/
You can see this:
http://chriscavanagh.wordpress.com/2010/10/04/a-real-net-4-0-webbrowser/