TinyHtml.Wpf 1.2.2

dotnet add package TinyHtml.Wpf --version 1.2.2
NuGet\Install-Package TinyHtml.Wpf -Version 1.2.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TinyHtml.Wpf" Version="1.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TinyHtml.Wpf --version 1.2.2
#r "nuget: TinyHtml.Wpf, 1.2.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TinyHtml.Wpf as a Cake Addin
#addin nuget:?package=TinyHtml.Wpf&version=1.2.2

// Install TinyHtml.Wpf as a Cake Tool
#tool nuget:?package=TinyHtml.Wpf&version=1.2.2

TinyHtml.Wpf

Introduction

TinyHtml.Wpf is a WPF HTML rendering library based on litehtml. It provides the rendering backend for WPF. Contrary to similar libraries it uses native WPF drawing to render texts, images and other stuff. So it is fully capable of doing high dpi and blends seemlessly with other content.

Originally it was developed by me to replace HTMLayout that we used before. However text rendering was always blocky and didn't blend well with other WPF content. We use this extensively for dynamic formatted text that is authored as HTML.

This library does not provide scripting capabilities or very advanced HTML. It proved to be quite capable nonetheless.

A Nuget package can be found on nuget.org. It supports x86 and x64 (or AnyCPU) applications.

Release Notes

1.2.2.0

  • .NET 5.0 build
  • Fixes possible access violation if control is unloaded while mouse cursor is inside of control

1.2.1.0

  • .NET Core 3.0 build
  • Upgrade to Visual Studio 2019

1.2.0.0

  • New virtual method OnAnchorClicked for WpfHtmlControlBase that allows interception of user clicks on links.

Requirements

  • .NET 4.6 or .NET Core 3.0
  • A WPF application
  • Visual Studio 2019 for building

Supported features

  • WPF Text rendering
  • HTML Tables
  • HTML Lists
  • Images
  • css
  • and much more...

Building

  1. Get sources from https://github.com/fsdsabel/TinyHtmlWpf: <br/><pre><code>git clone --recursive https://github.com/fsdsabel/TinyHtmlWpf.git</code></pre>
  2. Open the Solution TinyWpfHtml.sln in Visual Studio 2019
  3. Compile configuration Release - x86
  4. Compile configuration Release - x64
  5. Binaries should be in Bin directory and HtmlTestApp should run

Usage

Basically there is only one class you need. It is WpfHtmlControl which is subclassed from a standard WPF Control. This control loads a default master style sheet. If you want a custom one, you can derive from WpfHtmlControlBase and load your own.

The master style sheet is used for all the default HTML elements like paragraphs or bold elements. For example you could do something like this:

public class MyWpfHtmlControl : WpfHtmlControlBase
{
    static MyWpfHtmlControl()
    {
        using (var s = typeof (MyWpfHtmlControl).Assembly.GetManifestResourceStream(typeof (MyWpfHtmlControl), "master.css"))
        {
            SetMasterStylesheet(new StreamReader(s).ReadToEnd());
        }
    }
}

You would then use MyWpfHtmlControl in your application.

The most basic usage of a WpfHtmlControl would be:

<local:WpfHtmlControl Background="Blue" Foreground="Red" FontSize="16" 
                      Html="&lt;b&gt;Hello world!&lt;/b&gt;"></local:WpfHtmlControl>

It is possible to bind to the Html property to update the displayed HTML dynamically.

If you want to display images, you have to override OnLoadResource.

License

Copyright (c) 2020, Daniel Sabel
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
  • Neither the name of the <organization> nor the
    names of its contributors may be used to endorse or promote products
    derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This library uses litehtml:

Copyright (c) 2013, Yuri Kobets (tordex)
All rights reserved.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net5.0-windows7.0 is compatible.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
.NET Framework net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.0

    • No dependencies.
  • .NETFramework 4.6

    • No dependencies.
  • net5.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.2 9,113 1/8/2021
1.2.1 1,481 6/22/2020
1.2.0 8,440 9/27/2018
1.1.0 1,661 3/26/2018
1.0.0.8 1,948 4/2/2017

1.2.2.0 - Fixed access violation when document was unloaded and WPF control received a mouse event
             - Support for .NET 5.0
     1.2.1.0 - Support for .NET Core 3.0
     1.2.0.0 - implemented use of links
     1.1.0.0 - streamlined package install, build and deployment