Skip to content

Utililty to inject HTML into a XAML RichTextBlock

Notifications You must be signed in to change notification settings

xleon/HTML2XAML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a UWP class library to inject HTML into a RichTextBlock easily

Usage:

  1. In a XAML file, declare the namespace:
xmlns:html="using:XAMLHtml" 
  1. In RichTextBlock controls, set or databind the Html property:
<RichTextBlock html:Properties.Html="{Binding ...}"/>

or

<RichTextBlock>
    <html:Properties.Html>
        <![CDATA[
            <p>This is a list:</p>
            <ul>
                <li>Item 1</li>
                <li>Item 2</li>
                <li>Item 3</li>
            </ul>
		]]>
	</html:Properties.Html>
</RichTextBlock>

h1, h2 and h3 tag can apply a custom format with the following code:

HtmlProperties.H2SpanFactory = () => new Span
{
    FontSize = 13.71,
    FontWeight = FontWeights.Light
};

To set a max width/height of <img> tags:

HtmlProperties.ImageMaxPixelWidth = 500;
HtmlProperties.ImageMaxPixelHeight = 500;

All credits to https://blogs.msdn.microsoft.com/tess/2013/05/13/displaying-html-content-in-a-richtextblock/

About

Utililty to inject HTML into a XAML RichTextBlock

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages