Skip to content

HtmlView

Rico Suter edited this page Jan 13, 2016 · 12 revisions
  • Package: MyToolkit.Extended
  • Platforms: WP7SL, WP8SL, WinRT, UWP

With this control you can display HTML without using the WebBrowser control. The control uses an extendable parser which generates native controls.

The following UI control generators are implemented:

  • Paragraph (p and h1/h2/h3 tags): ParagraphGenerator
  • Italic and bold font (em and strong tag)
  • Link (a tag)
  • Image (img tag)
  • Unordered lists (ul and li tags)

If you need scrollbars, use the ScrollableHtmlView control for much better performance (instead of putting the HtmlView into a ScrollViewer).

Change tag rendering styles

The generated HTML elements can be enhanced or changed by adding or modifying existing generators:

MyHtmlView.GetGenerator<ParagraphGenerator>("h1").FontWeight = FontWeights.Bold;
MyHtmlView.GetGenerator<ParagraphGenerator>("h2").FontWeight = FontWeights.Bold;
MyHtmlView.GetGenerator<ParagraphGenerator>("h3").FontWeight = FontWeights.Bold;

It is also possible to implement new generators for other HTML tags. If the generators are changed when the HTML is already set, call MyHtmlView.Refresh() to rerender the HTML.

Use default text foreground brush for links

HtmlView.GetGenerator<LinkGenerator>("a").Foreground = 
    (Brush) Resources["ApplicationForegroundThemeBrush"];

Notes

  • Some generators are missing in the WinRT version.
Clone this wiki locally