简体   繁体   English

如何使页面适合Silverlight WebBrowser控件?

[英]How to fit page to Silverlight WebBrowser control?

I use WebBrowser Silverlight 4 control to load some page: 我使用WebBrowser Silverlight 4控件加载某些页面:

<WebBrowser Height="350" Name="webBrowser" Width="400" />
...
webBrowser.Navigate(new Uri("http://mail.live.com")); 

But page loads with horizontal and vertical scroll bars. 但是页面加载了水平和垂直滚动条。 So I'm trying to find some ways to get actual size of loaded page (then I can change Height/Width of control) OR change scale of loaded page (to fit it to the actual WebControl control). 因此,我试图找到一些方法来获取加载页面的实际大小(然后可以更改控件的高度/宽度) 更改加载页面的比例(以使其适合实际的WebControl控件)。 Is it possible to do with standard WebControl methods? 是否可以使用标准的WebControl方法?

The web browser component in Silverlight is a COM component that is wrapped by a Silverlight control. Silverlight中的Web浏览器组件是一个由Silverlight控件包装的COM组件。

You have two options. 您有两个选择。 1) Make the web site fluid inside the browser so that it will shrink with the browser. 1)使网站在浏览器内部流动,以便随浏览器收缩。

Or 要么

2) The only way that you could "shrink" the web site would be to set the Zoom. 2)可以“缩小”网站的唯一方法是设置“缩放”。 There is a link to do this here by tricking the mouse scroll wheel into zooming it for you. 这里有一个链接,可以通过诱骗鼠标滚轮为您缩放来实现。

http://forums.silverlight.net/forums/p/200177/466986.aspx http://forums.silverlight.net/forums/p/200177/466986.aspx

Got you. 知道了 Usually you can do that using the ViewBox, but it doesn't work with Webbrowser unfortunately. 通常,您可以使用ViewBox来执行此操作,但是不幸的是,它不适用于Webbrowser。 I guess you will have to wait for the next version of Webbrowser :( 我想您将不得不等待Webbrowser的下一个版本:(

--Old answer below: -下面的旧答案:

I'm not sure if i understood your problem correctly, do you want the webbrowser to fit its parent container? 我不确定我是否正确理解了您的问题,您是否希望Web浏览器适合其父容器?

Maybe using HorizontalContentAlignment and VerticalContentAlignment like this? 也许像这样使用Horizo​​ntalContentAlignment和VerticalContentAlignment吗?

<ScrollViewer HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
     <WebBrowser Name="webBrowser" />
</ScrollViewer>

Could you explain better? 你能解释得更好吗?

Cheers 干杯

You can shrink a WebBrowser control by wrapping it into a ViewBox control and then setting the Width and Height on the ViewBox instead of the web browser. 您可以通过将WebBrowser控件包装到ViewBox控件中,然后在ViewBox而不是Web浏览器上设置Width和Height来缩小WebBrowser控件。 You will also need to set the Stretch property on the viewbox to Uniform. 您还需要将视图框上的Stretch属性设置为Uniform。

<ViewBox x:Name="MyViewBox" Width="350" Height="350" Stretch="Uniform">
    <WebBrowser x:Name="MyWebBrowser" Source="...." />
</ViewBox>

HTH. HTH。

If this helps, please mark as answer. 如果有帮助,请标记为答案。 Thanks, 谢谢,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使Google身份验证页面适合我的Web浏览器控件? - How to make Google authentication page fit in my webbrowser control? 如何调试嵌入在WebBrowser控件中的Silverlight? - How to debug Silverlight embedded in a WebBrowser Control? 如何防止Silverlight Webbrowser控件在新窗口中打开链接? - How to prevent Silverlight Webbrowser Control to open links in new windows? 如何在Silverlight 4中从WebBrowser控件平滑过渡到图像? - How to make smooth transition from a WebBrowser control to an Image in Silverlight 4? 每次重新访问应用程序页面时,WebBrowser控件都必须重新加载内容(Windows Phone 7,Silverlight) - WebBrowser control must reload content every time app page is revisited (Windows Phone 7, Silverlight) 在托管WebBrowser控件的应用程序中,如何在由WebBrowser控件查看的页面中调用JavaScript函数? - How might I call a JavaScript Function in a Page Viewed by a WebBrowser Control from the Application Hosting the WebBrowser Control? ASPX页面中的Silverlight控件 - Silverlight control in aspx page WebBrowser控件页面加载错误 - WebBrowser control page load error 如何在Windows Forms WebBrowser控件中的页面上调用Click事件? - How to call the Click event on a page in the Windows Forms WebBrowser control? WebBrowser控件:如何使其最大化 - WebBrowser control: how to maximize it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM