网页浏览器不显示内容
我在 WP7 中遇到 WebBrowser 控件问题。谁能向我解释为什么示例 1 有效而示例 2 无效?
示例 1:
XAML
<Grid x:Name="grForWebBrowser">
<phone:WebBrowser Name="wb"/>
</Grid>
CodeBehind
const string html = "<html><h2>TEST</h2></html >";
wb.NavigateToString(html);
示例 2:
XAML
<StackPanel x:Name="spForWebBrowser"/>
CodeBehind
WebBrowser wb = new WebBrowser();
const string html = "<html><h2>TEST</h2></html>";
wb.NavigateToString(html);
spForWebBrowser.Children.Add(wb);
感谢您的建议。
I'm having a problem with WebBrowser control in WP7. Can anyone explain to me why does example 1 works and example 2 doesn't?
Example 1:
XAML
<Grid x:Name="grForWebBrowser">
<phone:WebBrowser Name="wb"/>
</Grid>
CodeBehind
const string html = "<html><h2>TEST</h2></html >";
wb.NavigateToString(html);
Example 2:
XAML
<StackPanel x:Name="spForWebBrowser"/>
CodeBehind
WebBrowser wb = new WebBrowser();
const string html = "<html><h2>TEST</h2></html>";
wb.NavigateToString(html);
spForWebBrowser.Children.Add(wb);
Thank you for any advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码确实有效。您只是还没有设置 webBroswer 的宽度和高度属性,因此它默认为 0 x 0
您还可以使用边距控制 WebBrowser 的大小,但为了解释起见,我明确设置了它的尺寸。
Your code does work. You just haven't set the width and height properties of the webBroswer so it is defaulting to 0 x 0
You could also control the size of the WebBrowser using Margins, but for the sake of explanation I explicitly set it's dimensions.