本文介绍了WPF:如何在弹出窗口中自动调整大小web浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹出 web浏览器内(见下文code)。 web浏览器有 =了maxWidth800。我想自动大小web浏览器到其内容的高度高度将其加载网站后,所以它不需要垂直滚动条。

我试过设置 HEIGHT =自动了maxHeight =5000,但我没有得到正确的结果。

你能帮助我该怎么办呢?非常感谢你!

 <弹出NAME =popup1VerticalOffset =3>
        &所述;边界了borderThickness =1>
            <&DockPanel中GT;
                <的ScrollViewer了maxHeight =700VerticalScrollBarVisibility =自动>
                    < web浏览器名称=WB1了maxWidth =800/>
                < /&的ScrollViewer GT;
            < / DockPanel中>
        < /边框>
    < /弹出>


解决方案

下面是解决方案:

 <弹出X:NAME =弹出WIDTH =800>
    &所述;边界了borderThickness =1>
        < web浏览器
            X:NAME =web浏览器
            LoadCompleted =WebBrowser_OnLoadCompleted
            ... />
    < /边框>
< /弹出>

处理器:

 私人无效WebBrowser_OnLoadCompleted(对象发件人,NavigationEventArgs E){
    this.Popup.Height =(INT)(this.WebBrowser.Document动态).body.scrollHeight + 20;
}

I have a Popup with a WebBrowser inside (see code below). The WebBrowser have MaxWidth = "800". I want auto-size the height of WebBrowser to its content height after it load website, so it dont need vertical ScrollBar.

I tried set Height = "Auto" or MaxHeight = "5000", but I dont get right result.

Can you help me how to do it? Thank you very much!

    <Popup Name="popup1" VerticalOffset="3">
        <Border BorderThickness="1">
            <DockPanel>
                <ScrollViewer MaxHeight="700" VerticalScrollBarVisibility="Auto">
                    <WebBrowser Name="wb1" MaxWidth="800"/>
                </ScrollViewer>
            </DockPanel>
        </Border>
    </Popup>
解决方案

Here is the solution:

<Popup x:Name="Popup" Width="800">
    <Border BorderThickness="1">
        <WebBrowser
            x:Name="WebBrowser"
            LoadCompleted="WebBrowser_OnLoadCompleted"
            ... />
    </Border>
</Popup>

Handler:

private void WebBrowser_OnLoadCompleted(object sender, NavigationEventArgs e) {
    this.Popup.Height = (int) (this.WebBrowser.Document as dynamic).body.scrollHeight + 20;
}

这篇关于WPF:如何在弹出窗口中自动调整大小web浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 08:15