缩放 WPF-WebBrowser-控制内容 [英] Zoom WPF-WebBrowser-Control Content

查看:24
本文介绍了缩放 WPF-WebBrowser-控制内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 wpf WebBrowser 控件中显示一个网站.但是内容太大了,所以你可以在这里看到滚动条:

I´d like to show a website inside the wpf WebBrowser Control. But the content size is to large, so that there are scrollbars as you can see here:

我想在这个窗口中显示整个网站,而不调整它的大小.我想放大页面内部,使其看起来像这样:

I would like to display the whole site in this window, without resizing it. I´d like to zoom inside the page so that it looks like this:

我想阻止使用 JavaScript 执行此操作.此处显示的 WPF 方式WPF WebBrowser - 如何缩放内容?也没有'不适合我.它总是说 mshtml.IHTMLDocument2 为空.

I´d like to prevent doing it with JavaScript. The WPF way shown here WPF WebBrowser - How to Zoom Content? also didn´t work for me. It always says the mshtml.IHTMLDocument2 is null.

我也想阻止使用 WindowsForms 进行.我希望有一个唯一的 XAML" - 解决这个问题的方法.

I also like to prevent doing it with WindowsForms. I hope there is a "only XAML" - way to solve this problem.

这是我的代码:

<Window x:Class="BrowserApp.MainWindow"

 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <WebBrowser Source="https://www.google.de/"></WebBrowser>
        </Grid>
    </Window>

谢谢!

编辑

这是我在 Webbrowser1_Navigated-Method 中的代码,其中发生 HRESULT: 0x80020101-Error.

This is my code inside the Webbrowser1_Navigated-Method, where the HRESULT: 0x80020101-Error occurs.

private void Webbrowser1_Navigated(object sender, NavigationEventArgs e)
{
    double Zoom = 0.5;
    mshtml.IHTMLDocument2 doc = Webbrowser1.Document as mshtml.IHTMLDocument2;
    doc.parentWindow.execScript("document.body.style.zoom=" + Zoom.ToString().Replace(",", ".") + ";");
}

推荐答案

webBrowser.LoadCompleted += Web_LoadCompleted;

private void Web_LoadCompleted (object sender, NavigationEventArgs e)
{
    // Place your code here
}

这篇关于缩放 WPF-WebBrowser-控制内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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