locked
RichTextBlock shows content as plain text RRS feed

  • Question

  • Hi,

    when developing a Windows 8 app, I have problems trying to render a text with HTML tags in a RichTextBlock control. That is, the content does not appear as it was expected but as plain text. I don't know if someone else had this problem, in that case I would apreciate any suggestion.

    Thanks in advance.

    Thursday, June 20, 2013 7:10 AM

Answers

  • Hi,

    I finally used the WebView control and decided to postpone the use of a parser solution for the next version of the app.

    The ConverToText method wasn't a full solution.Because of the way it works some elements as images weren't render:  "TheConvertToText method will only parse HTML-formatted data to extract the text".

    Thanks a lot! :)

    Monday, July 8, 2013 7:11 AM

All replies

  • How exactly are you trying to render the text?

    RichTextBlock does not implement HTML. The HTML formatting tags are invalid.

    If you want to display HTML use a WebView control.

    --Rob


    Thursday, June 20, 2013 7:41 AM
    Moderator
  • I have a string variable which cointains text in HTML format and then I made a binding to this variable in the RichTextBlock control.

    When debugging the text I read was:

    <P> Lorem ipsum dolor sit amet, consectetur adipiscing elit. </P><P> Ut non libero viverra, posuere neque vel, consectetur mi. Donec in condimentum massa. </P>

    instead of

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.

    Ut non libero viverra, posuere neque vel, consectetur mi. Donec in condimentum massa.


    But then I used HtmlUtilities.ConvertToText() as suggested in http://social.msdn.microsoft.com/Forums/en-US/4eb58bba-dfe5-488b-946a-6d7167222771/how-to-convert-html-to-a-richtextblock-content and now I can see the text as expected. The only things that remain failing are the hyperlinks and images, because the method only extract the text so I have to discover how to show this elements.

    Thanks for your response! :D

    Thursday, June 20, 2013 7:59 AM
  • Hi!

    I think a solution could be to extract each node of the HTML text and depending of their name create inlineuicontainer objects based on their attributes and finally add them no a paragraph object which will be use in the binding of the RichTextBlock control.

    But...I don't know why the Inlines.Add method is not working... :S

    What do you think?!

    Thursday, June 20, 2013 9:27 AM
  • Hi,

    I finally used the WebView control and decided to postpone the use of a parser solution for the next version of the app.

    The ConverToText method wasn't a full solution.Because of the way it works some elements as images weren't render:  "TheConvertToText method will only parse HTML-formatted data to extract the text".

    Thanks a lot! :)

    Monday, July 8, 2013 7:11 AM