[英]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? 也许像这样使用HorizontalContentAlignment和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.