簡體   English   中英

如何在Windows Phone 7中自動調整WebBrowser控件的高度?

[英]How to auto adjust WebBrowser control height in Windows Phone 7?

我已經在xaml中創建了一個WebBrowser控件,並通過字符串將一些html綁定到了它。 工作正常。 但是WebBrowser永遠不會自動調整其高度。

<phone:WebBrowser
    HorizontalAlignment="Stretch" 
    Margin="0,6,0,0" Name="myWebView" 
    VerticalAlignment="Top" />

private void WebBrowser_OnLoaded(object sender, RoutedEventArgs e)
{
    String htmlTags = "<html><head><meta charset='UTF-8'/><meta name=\"viewport\" content=\"width='480', initial-scale='1'\"></head><body><center>{0}</center></body></html>";
    myWebView.NavigateToString(String.Format(htmlTags, getHTMLContent());
}

public string getHTMLContent()
{
    StringBuilder htmlBody = new StringBuilder();
    htmlBody.Append("<table cellpadding=\"0\" cellspacing=\"0\" width=\"704\" height=\"484\" background=\"https://known.com/img/back/123456.jpg\" style=\"background-repeat: no-repeat; background-position: center;\">");
    htmlBody.Append("<tr>");
    htmlBody.Append("<td valign=top>");
    htmlBody.Append("<div style=\"position: absolute;\">");
    htmlBody.Append("<div style=\"position: absolute; display: table; width: 132px; height: 132px; top: 44px; left: 44px; z-index:0;\">");
    htmlBody.Append("<img src=\"https://known.com/img/icon/87654.jpg\" width=\"100%\" height=\"100%\"/>");
    htmlBody.Append("</div>");
    htmlBody.Append("<div style=\"position: absolute; display: table; width: 704px; height: 484px; top: 0px; left: 0px; z-index:0; \">");
    htmlBody.Append("<img src=\"https://known.com/img/icon/234255.jpg\" width=\"100%\" height=\"100%\"/>");
    htmlBody.Append("</div>");
    htmlBody.Append("<div style=\"position: absolute; display: table; width: 440px; height: 264px; top: 184px; left: 184px; z-index:0;  font-family:times;  font-size:14px;  color:#FFFFFF; \" align=\"center\">");
    htmlBody.Append("<div style=\"display: table-cell;vertical-align: middle;\">");
    htmlBody.Append("</div>");
    htmlBody.Append("</div>");
    htmlBody.Append("</div>");
    htmlBody.Append("</td>");
    htmlBody.Append("</tr>");
    htmlBody.Append("</table>");
    return htmlBody.ToString();
}

我希望WebBrowser成為

1)自動調整其高度取決於HTML字符串。 如果我僅通過一張圖像,則應根據圖像自動調整。 它沒有內容的意思,瀏覽器應該隱藏自己。

2)不應滾動,因為WebBrowser已經拉伸其高度以適合內容。

我該怎么做? 請讓我有任何想法來解決我的問題。

您需要使用javascript獲取呈現的html的高度並將其設置為WebBrowser控件。

下面是一個實現

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM