等效于Windows Phone 7中的Html.fromHtml() [英] Equivalent to Html.fromHtml() in Windows phone 7

查看:61
本文介绍了等效于Windows Phone 7中的Html.fromHtml()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在显示中显示html内容.当我尝试使用网络浏览器时,它会显示内容.但是我们想要像Android一样显示TextBlock中的内容.我们使用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()的替代方法.

解决方案

在WP中,没有人需要看到HTML代码,至少没有技术用户,因此,您必须为RichTextBox控件创建和扩展方法 TextBlock Windows Phone 8.1中的文本格式,或者您可以使用此 http://www.kettic.com/winforms_ui/csharp_guide/panels_labels_label_text_format.shtml

Hi I want to show html contents in display. When I try with web browser it showing the content. But we want to show the contents in TextBlock like android. We using HTML.fromHtml() to show the html contents in TextView. Please help me to find the alternative for HTML.fromHtml() in windows phone 7.

We try with web browser:

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();
        }

But we can not use this in our project due to client requirements. Please help us to find the alternative for HTML.fromHtml() in windows phone 7.

解决方案

In WP, nobody needs to see HTML code, at least, no-technical users, so, you must create and extension method for the RichTextBox Control Text formatting in TextBlock Windows Phone 8.1 or you can use this http://www.kettic.com/winforms_ui/csharp_guide/panels_labels_label_text_format.shtml

这篇关于等效于Windows Phone 7中的Html.fromHtml()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆