开发者

How to convert HTML to RichTextBox in Windows Phone Mango

开发者 https://www.devze.com 2023-04-03 14:42 出处:网络
Is there an easy way to convert HTML to display in the new Windows Phone 7.开发者_高级运维1 (Mango) RichTextBox control.I\'m mostly concerned about retaining links and images without using a web brows

Is there an easy way to convert HTML to display in the new Windows Phone 7.开发者_高级运维1 (Mango) RichTextBox control. I'm mostly concerned about retaining links and images without using a web browser control.

thanks, Sam


I would use HTML Agility pack to parse the HTML and transform each type of node in the equivalent in the Document namespace: http://htmlagilitypack.codeplex.com/

You need to handle the nested elements and depending of the level of conformity of the HTML, handling bad formatted content can be hard but HA is a good library.

There's a sample in the source code I think.


  public void ConvertRtfToHtml()
  {
    System.Windows.Forms.WebBrowser webBrowser = 
                                           new System.Windows.Forms.WebBrowser();
    webBrowser.CreateControl(); // only if needed
    webBrowser.DocumentText = richTextBox1.Text;
    while (webBrowser.DocumentText != richTextBox1.Text)
      Application.DoEvents();
    webBrowser.Document.ExecCommand("SelectAll", false, null);
    webBrowser.Document.ExecCommand("Copy", false, null);
    richTextBox2.Paste();
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消