网页浏览器不显示内容

发布于 2025-01-01 13:12:14 字数 695 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

压抑⊿情绪 2025-01-08 13:12:14

你的代码确实有效。您只是还没有设置 webBroswer 的宽度和高度属性,因此它默认为 0 x 0

WebBrowser wb = new WebBrowser();
string html = "<html><h2>TEST</h2></html>";
wb.NavigateToString(html);
wb.Height = 150.0;
wb.Width=440.0;
spForWebBrowser.Children.Add(wb);
// or 
grForWebBrowser.Children.Add(wb);

您还可以使用边距控制 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

WebBrowser wb = new WebBrowser();
string html = "<html><h2>TEST</h2></html>";
wb.NavigateToString(html);
wb.Height = 150.0;
wb.Width=440.0;
spForWebBrowser.Children.Add(wb);
// or 
grForWebBrowser.Children.Add(wb);

You could also control the size of the WebBrowser using Margins, but for the sake of explanation I explicitly set it's dimensions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文