How to Display HTML output in RichEditBox in C# UWP

Jay 60 Reputation points
2024-05-09T07:19:57.2533333+00:00

This is a RichTextEditor, and I want to display HTML output. Is it possible?

As seen below ss here is display HTML content as a string in Richtexteditor. Please Help if we have any solution for this

Sample string:

"Dear <customer>\r\r<notes>\r\rInvoice #<invoice#>\rInvoice Total Amount: <total>\r\r<paypal>\r<terms>\r<pdf_file>\r\r<attachment>\r\r<!DOCTYPE html>\r<html>\r<head>\r<title>Page Title</title>\r</head>\r<body>\r\r<h1>This is a Heading</h1>\r<p>This is a paragraph.</p>\r\r</body>\r</html>\r"
User's image

Universal Windows Platform (UWP)
{count} vote

Accepted answer
  1. Roy Li - MSFT 32,466 Reputation points Microsoft Vendor
    2024-05-10T02:14:20.58+00:00

    Hello,

    Welcome to Microsoft Q&A!

    It will be more complicated if you really need to show HTML string in RichEditBox since there is no way that could directly import the string to it. There are two ways that might be possible to do this.

    The first one is to convert the HTML string to RTF that could be directly loaded by the RichEditBox. You might check if there are third party library that could do it otherwise you need to implement it by yourself.

    The second way is to parse the Html string by yourself. Generate the corresponding content based on the tag type by recursion in code, then write conversion methods for various tags. After that, you could directly set the content of the RichEditBox.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful