您好我想在显示中显示html内容。当我尝试使用网络浏览器时,它会显示内容。但我们想在TextBlock中显示像android这样的内容。我们使用HTML.fromHtml()在TextView中显示html内容。请帮我在windows phone 7中找到HTML.fromHtml()的替代方案。
我们尝试使用网络浏览器:
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();
}
但是由于客户要求,我们不能在我们的项目中使用它。请帮助我们在Windows Phone 7中找到HTML.fromHtml()的替代方案。
答案 0 :(得分:0)
在WP中,没有人需要查看HTML代码,至少是非技术用户,因此,您必须为RichTextBox Control Text formatting in TextBlock Windows Phone 8.1创建和扩展方法,或者您可以使用此http://www.kettic.com/winforms_ui/csharp_guide/panels_labels_label_text_format.shtml